diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/ci-cd.yaml index d3572de..0192c30 100644 --- a/.gitea/workflows/ci-cd.yaml +++ b/.gitea/workflows/ci-cd.yaml @@ -137,6 +137,57 @@ jobs: container: image: ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}-build-cache:${{ needs.build-cache.outputs.deps_hash }} + docker-push: + name: Docker Push + needs: [build-cache, ci-pipeline] + runs-on: ubuntu-latest-ca + if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'ci-bot' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feature/move-docker-job')" + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.CI_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.PACKAGES_TOKEN }} + + - name: Build and push Docker image + run: | + source VERSION + IMAGE_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}" + + # Use the template file with proper dependency hash replacement + DEPS_HASH="${{ needs.build-cache.outputs.deps_hash }}" + echo "Using dependency hash: $DEPS_HASH" + + # Create Dockerfile.prod from template + sed "s/{{DEPS_HASH}}/$DEPS_HASH/g" docker/Dockerfile.prod.template > docker/Dockerfile.prod + + TAGS="$IMAGE_VERSION latest ${{ github.sha }}" + echo "Building Docker image with tags: $TAGS" + + # Build the production image + docker build -t dance-lessons-coach -f docker/Dockerfile.prod . + + for TAG in $TAGS; do + IMAGE_NAME="${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:$TAG" + echo "Tagging and pushing: $IMAGE_NAME" + docker tag dance-lessons-coach "$IMAGE_NAME" + docker push "$IMAGE_NAME" + done + + - name: Show published images + run: | + source VERSION + IMAGE_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}" + echo "📦 Published Docker images:" + echo " - ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:$IMAGE_VERSION" + echo " - ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:latest" + echo " - ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:${{ github.sha }}" + services: postgres: image: postgres:15 @@ -304,9 +355,19 @@ jobs: echo "ℹ️ No changes to push" fi - # Docker build and push (main branch only) + + + docker-push: + name: Docker Push + needs: [build-cache, ci-pipeline] + runs-on: ubuntu-latest-ca + if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'ci-bot' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feature/move-docker-job')" + + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Login to Gitea Container Registry - if: github.ref == 'refs/heads/main' uses: docker/login-action@v3 with: registry: ${{ env.CI_REGISTRY }} @@ -314,7 +375,6 @@ jobs: password: ${{ secrets.PACKAGES_TOKEN }} - name: Build and push Docker image - if: github.ref == 'refs/heads/main' run: | source VERSION IMAGE_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}" @@ -340,7 +400,6 @@ jobs: done - name: Show published images - if: github.ref == 'refs/heads/main' run: | source VERSION IMAGE_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}" diff --git a/issue_data.json b/issue_data.json new file mode 100644 index 0000000..99fa44a --- /dev/null +++ b/issue_data.json @@ -0,0 +1 @@ +{"title": "Move Docker push steps to separate job", "body": "The current CI/CD workflow has Docker push steps in the second job that runs in a container. The container doesn't have Docker commands available. Need to move these steps to a new third job that runs on ubuntu-latest-ca without using a container."}