From 0e480232589442b8bc4e910919f91e691def01a3 Mon Sep 17 00:00:00 2001 From: k1nq Date: Sun, 30 Nov 2025 00:18:19 +0500 Subject: [PATCH] fix: add migrations service to docker-compose and update build workflow for migrations image --- .gitea/workflows/build.yml | 8 +++++++- docker-compose-ci.yml | 20 ++++++++++++++++++-- migrations/Dockerfile | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 migrations/Dockerfile diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 8a2e6eb..cd01663 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -21,6 +21,11 @@ jobs: docker build -t ${{ secrets.GIT_HOST }}/${{ gitea.repository }}:app -f app/Dockerfile . docker push ${{ secrets.GIT_HOST }}/${{ gitea.repository }}:app + - name: Build and push migrations image + run: | + docker build -t ${{ secrets.GIT_HOST }}/${{ gitea.repository }}:migrations -f migrations/Dockerfile . + docker push ${{ secrets.GIT_HOST }}/${{ gitea.repository }}:migrations + deploy: runs-on: ubuntu-latest needs: build @@ -28,7 +33,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Instasll SSH key + - name: Install SSH key uses: webfactory/ssh-agent@v0.9.0 with: ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }} @@ -47,6 +52,7 @@ jobs: ssh ${{ secrets.LXC_USER }}@${{ secrets.LXC_HOST }} << 'EOF' echo "${{ secrets.TOKEN }}" | docker login ${{ secrets.GIT_HOST }} -u ${{ secrets.USERNAME }} --password-stdin docker pull ${{ secrets.GIT_HOST }}/${{ gitea.repository }}:app + docker pull ${{ secrets.GIT_HOST }}/${{ gitea.repository }}:migrations cd /srv/app docker compose up -d --force-recreate docker image prune -f diff --git a/docker-compose-ci.yml b/docker-compose-ci.yml index 5bfeeba..dc7fae8 100644 --- a/docker-compose-ci.yml +++ b/docker-compose-ci.yml @@ -26,8 +26,24 @@ services: ports: - "80:8000" depends_on: - - postgres - - redis + postgres: + condition: service_started + redis: + condition: service_started + migrations: + condition: service_completed_successfully + + migrations: + image: ${GIT_HOST}/${GIT_USER}/${GIT_REPO}:migrations + restart: "no" + env_file: + - .env + environment: + DB_HOST: postgres + REDIS_URL: redis://redis:6379/0 + depends_on: + postgres: + condition: service_started postgres: image: postgres:16-alpine diff --git a/migrations/Dockerfile b/migrations/Dockerfile new file mode 100644 index 0000000..f9c3ac3 --- /dev/null +++ b/migrations/Dockerfile @@ -0,0 +1,26 @@ +# syntax=docker/dockerfile:1.7 + +FROM ghcr.io/astral-sh/uv:python3.14-alpine AS builder +WORKDIR /opt/migrations + +COPY pyproject.toml uv.lock ./ +RUN uv sync --frozen --no-dev + +COPY app ./app +COPY migrations ./migrations +COPY alembic.ini . + +FROM python:3.14-alpine AS runtime +ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 +ENV PATH="/opt/app/.venv/bin:${PATH}" +WORKDIR /opt/app + +RUN apk add --no-cache postgresql-libs + +COPY --from=builder /opt/migrations/.venv /opt/app/.venv +COPY app ./app +COPY migrations ./migrations +COPY alembic.ini . +COPY pyproject.toml . + +ENTRYPOINT ["alembic", "upgrade", "head"] \ No newline at end of file