diff --git a/Migrate.Dockerfile b/Migrate.Dockerfile new file mode 100644 index 0000000..938e05f --- /dev/null +++ b/Migrate.Dockerfile @@ -0,0 +1,18 @@ +FROM postgres:15.3-alpine +WORKDIR /var +RUN apk update && \ + apk add jq wget +RUN mkdir /var/migrations && \ +# Create a list of download URLs for migration files + wget -q -O - https://api.github.com/repos/open-sauced/api/contents/migrations \ + | jq --raw-output '.[].download_url' \ + > ./original_urls.txt +# Downloads all SQL files into /var/migrations +RUN wget -q -P /var/migrations -i ./original_urls.txt && \ + cat /var/migrations/*.sql > /var/all-migrations.sql +# Rename password from environment and run file +CMD PGPASSWORD=${POSTGRES_PASSWORD} psql \ + --host db \ + --username postgres \ + --dbname postgres \ + -f /var/all-migrations.sql diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..74cc895 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +services: + db: + image: postgres:15.3-alpine + ports: + - "5432:5432" + environment: + - POSTGRES_PASSWORD=pw + healthcheck: + test: ["CMD-SHELL", "pg_isready", "-U", "postgres"] + interval: 30s + timeout: 10s + retries: 3 + migrate: + build: + dockerfile: Migrate.Dockerfile + context: . + environment: + - POSTGRES_PASSWORD=pw + depends_on: + db: + condition: service_healthy + app: + image: golang:1.20-alpine + ports: + - "8080:8080" + depends_on: + db: + condition: service_healthy + migrate: + condition: service_completed_successfully + volumes: + - .:/app + working_dir: /app + command: go run main.go -sslmode-disable -debug + environment: + - DATABASE_PORT=5432 + - DATABASE_HOST=db + - DATABASE_USER=postgres + - DATABASE_PASSWORD=pw + - DATABASE_DBNAME=postgres + - SERVER_PORT=8080 + - GIT_PROVIDER=cache + - CACHE_DIR=/tmp + - MIN_FREE_DISK_GB=25