name: Go CD on: push: branches: [main] tags: ["v*"] jobs: build-and-push: name: Build and Push Docker Image runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Check out code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} tags: | type=ref,event=branch type=ref,event=tag type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,format=long - name: Build and push uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max deploy-staging: name: Deploy to Staging needs: build-and-push runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') steps: - name: Check out code uses: actions/checkout@v4 # This step runs the deployment command from the Makefile. # You will need to add secrets to your GitHub repository for this to work. # For example, SSH_PRIVATE_KEY, STAGING_HOST, etc. - name: Deploy to staging run: make deploy-staging env: # Example of how you might pass the tag to the makefile TAG: ${{ github.ref_name }} # Add other environment variables/secrets needed for deployment # STAGING_HOST: ${{ secrets.STAGING_HOST }} # STAGING_USER: ${{ secrets.STAGING_USER }} # SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}