This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Image | |
| on: | |
| push: | |
| branches: [main] | |
| env: | |
| GITHUB_REGISTRY: ghcr.io | |
| GITHUB_IMAGE_NAME: ${{ github.repository }}/core | |
| GCP_REGISTRY: europe-west4-docker.pkg.dev | |
| GCP_PROJECT_ID: nanoapi-registry | |
| GCP_REPOSITORY: nanoapi-registry | |
| GCP_IMAGE_NAME: stackcore/core | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Deno | |
| uses: denoland/setup-deno@v2 | |
| with: | |
| deno-version: v2.3.5 | |
| - name: Build Deno application | |
| run: | | |
| deno install --allow-scripts --reload | |
| deno task build:core | |
| # GitHub Container Registry login | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GITHUB_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # GCP Authentication | |
| - name: Authenticate to Google Cloud | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| # Configure Docker for GCP | |
| - name: Configure Docker for GCP Artifact Registry | |
| run: gcloud auth configure-docker ${{ env.GCP_REGISTRY }} | |
| # Build and push to both registries | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: packages/core | |
| file: packages/core/Dockerfile | |
| push: true | |
| tags: | | |
| ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.ref_name }} | |
| ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.sha }} | |
| ${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.ref_name }} | |
| ${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.sha }} | |
| # Output the image URLs for easy reference | |
| - name: Output image URLs | |
| run: | | |
| echo "Images pushed to:" | |
| echo "GitHub: ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.ref_name }}" | |
| echo "GitHub: ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.sha }}" | |
| echo "GCP: ${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.ref_name }}" | |
| echo "GCP: ${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.sha }}" |