Files
dance-lessons-coach/.gitea/workflows/docker-push.yaml

160 lines
5.6 KiB
YAML

---
# dance-lessons-coach Docker Push Workflow
# Separate workflow for Docker image building and pushing
# Can be triggered manually or by CI/CD workflow
name: Docker Push
on:
# Manual trigger for testing or production
workflow_dispatch:
inputs:
ref:
description: 'Git reference (branch/tag)'
required: false
type: string
default: ''
# Environment variables
env:
GITEA_INTERNAL: "https://gitea.arcodange.lab/"
GITEA_EXTERNAL: "https://gitea.arcodange.fr/"
GITEA_ORG: "arcodange"
GITEA_REPO: "dance-lessons-coach"
CI_REGISTRY: "gitea.arcodange.lab"
jobs:
docker-push:
name: Docker Push
runs-on: ubuntu-latest-ca
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.CI_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PACKAGES_TOKEN }}
- name: Calculate dependency hash
id: calc_hash
run: |
# Calculate dependency hash (same method as build-cache job)
DEPS_HASH=$(sha256sum go.mod go.sum docker/Dockerfile.build | sha256sum | cut -d' ' -f1 | head -c 12)
echo "Dependency hash: $DEPS_HASH"
echo "deps_hash=$DEPS_HASH" >> $GITHUB_OUTPUT
- name: Restore Swagger Docs Cache
id: cache-swagger-restore
uses: actions/cache/restore@v5
with:
path: |
pkg/server/docs/docs.go
pkg/server/docs/swagger.json
pkg/server/docs/swagger.yaml
key: swagger-docs-${{ hashFiles('cmd/server/main.go', 'pkg/greet/*.go', 'pkg/server/*.go', 'go.mod') }}
restore-keys: |
swagger-docs-
- name: Generate Swagger Docs if needed
if: steps.cache-swagger-restore.outputs.cache-hit != 'true'
run: >
docker run --rm
-v $(pwd):/workspace
-w /workspace
gitea.arcodange.lab/arcodange/dance-lessons-coach-build-cache:${{ steps.calc_hash.outputs.deps_hash }}
sh -c "ls -la && pwd && go generate ./pkg/server"
- name: Save Swagger Docs Cache
if: steps.cache-swagger-restore.outputs.cache-hit != 'true'
id: cache-swagger-save
uses: actions/cache/save@v5
with:
path: |
pkg/server/docs/docs.go
pkg/server/docs/swagger.json
pkg/server/docs/swagger.yaml
key: ${{ steps.cache-swagger-restore.outputs.cache-primary-key }}
- name: Build and push Docker image
run: |
source VERSION
IMAGE_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}"
# Use the calculated dependency hash and set it as environment variable
DEPS_HASH="${{ steps.calc_hash.outputs.deps_hash }}"
echo "Using dependency hash: $DEPS_HASH"
echo "DEPS_HASH=$DEPS_HASH" >> $GITHUB_ENV
TAGS="$IMAGE_VERSION latest ${{ github.sha }}"
echo "Building Docker image with tags: $TAGS"
# Build the production image using inline version with prebuilt cache image
# Fixed: Use $GITHUB_ENV variable in the inline Dockerfile
docker build -t dance-lessons-coach -f - --build-arg DEPS_HASH . <<EOF
# dance-lessons-coach Production Docker Image
# Inline Dockerfile using prebuilt cache image
# Use the build cache image as base
ARG DEPS_HASH
FROM gitea.arcodange.lab/arcodange/dance-lessons-coach-build-cache:${DEPS_HASH} AS builder
# Copy source code to the correct working directory
COPY . /workspace
# Set working directory and build the binary
WORKDIR /workspace
RUN go build -o dance-lessons-coach ./cmd/server
# Final minimal image
FROM alpine:3.18
WORKDIR /app
# Install minimal dependencies
RUN apk add --no-cache ca-certificates tzdata
# Copy binary from builder
COPY --from=builder /workspace/dance-lessons-coach /app/dance-lessons-coach
# Copy configuration
COPY config.yaml /app/config.yaml
# Set permissions
RUN chmod +x /app/dance-lessons-coach
# Set timezone
ENV TZ=UTC
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget -q --spider http://localhost:8080/api/health || exit 1
# Entry point
ENTRYPOINT ["/app/dance-lessons-coach"]
EOF
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 }}"