Skip to content

Commit

Permalink
chore: test flyway clean
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellmueller committed Dec 24, 2024
1 parent 7b79443 commit 0d3cf9f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
9 changes: 9 additions & 0 deletions infrastructure/api/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ resource "aws_ecs_task_definition" "node_api_task" {
image = "${var.flyway_image}"
essential = false
environment = [
{
name = "APP_ENV"
value = local.rds_app_env
},
{
name = "FLYWAY_URL"
value = "jdbc:postgresql://${data.aws_rds_cluster.rds_cluster.endpoint}/${var.db_name}"
Expand All @@ -71,6 +75,11 @@ resource "aws_ecs_task_definition" "node_api_task" {
{
name = "FLYWAY_CONNECT_RETRIES"
value = "2"
},
{
# This defaults to true, though we want to enable it only in dev to reset the database
name = "FLYWAY_CLEAN_DISABLED"
value = contains(["dev"], local.rds_app_env) ? "false" : "true"
}
]

Expand Down
21 changes: 16 additions & 5 deletions migrations/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
FROM flyway/flyway:10-alpine
FROM flyway/flyway:11-alpine

# Copy migrations
COPY ./sql /flyway/sql

# Non-root user
RUN adduser -D app
# Copy entrypoint script
COPY entrypoint.sh /flyway/entrypoint.sh
RUN chmod +x /flyway/entrypoint.sh

# Set correct permissions for non-root user
RUN adduser -D app && chown -R app:app /flyway/sql

# Switch to non-root user
USER app

# Health check and startup
HEALTHCHECK CMD info
# Health check
HEALTHCHECK CMD flyway info || exit 1

# Set the custom entrypoint
ENTRYPOINT ["/flyway/entrypoint.sh"]

# Default command
CMD ["info", "migrate", "info"]
14 changes: 14 additions & 0 deletions migrations/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
set -e

# Check APP_ENV and run flyway clean if it is set to 'dev'
# FLYWAY_CLEAN_DISABLED will also have to be set to 'false' for this to work
if [ "$APP_ENV" = "dev" ]; then
echo "APP_ENV is set to 'dev'. Running flyway clean..."
flyway clean
else
echo "APP_ENV is not 'dev'. Skipping flyway clean."
fi

# Execute the passed arguments (default to Flyway commands)
exec flyway "$@"

0 comments on commit 0d3cf9f

Please sign in to comment.