Skip to content

Build and Push Docker Image #165

Build and Push Docker Image

Build and Push Docker Image #165

Workflow file for this run

name: Build and Push Docker Image
on:
pull_request:
types: [closed]
branches:
- tst
- prd
workflow_dispatch:
inputs:
branch:
description: 'Branch to trigger the workflow on (default: tst)'
required: false
default: tst
jobs:
build-and-push:
if: github.event_name == 'pull_request' || github.event.inputs.branch == 'tst'
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout 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 branch name and lowercase repository name
shell: bash
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "BRANCH_NAME=tst" >> $GITHUB_ENV
else
echo "BRANCH_NAME=$(echo ${GITHUB_BASE_REF} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
fi
echo "REPOSITORY_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set branch specific secrets
shell: bash
run: |
if [ "$BRANCH_NAME" == "prd" ]; then
echo "NEXT_PUBLIC_SUPABASE_URL=${{ secrets.NEXT_PUBLIC_SUPABASE_URL_PRD }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY=${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY_PRD }}" >> $GITHUB_ENV
echo "SUPABASE_SERVICE_ROLE_KEY=${{ secrets.SUPABASE_SERVICE_ROLE_KEY_PRD }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_SITE_URL=${{ secrets.NEXT_PUBLIC_SITE_URL_PRD }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_LOGFLARE_API_TOKEN=${{ secrets.NEXT_PUBLIC_LOGFLARE_API_TOKEN_PRD }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_LOGFLARE_CLIENT_TOKEN=${{ secrets.NEXT_PUBLIC_LOGFLARE_CLIENT_TOKEN_PRD }}" >> $GITHUB_ENV
elif [ "$BRANCH_NAME" == "tst" ]; then
echo "NEXT_PUBLIC_SUPABASE_URL=${{ secrets.NEXT_PUBLIC_SUPABASE_URL_TST }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY=${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY_TST }}" >> $GITHUB_ENV
echo "SUPABASE_SERVICE_ROLE_KEY=${{ secrets.SUPABASE_SERVICE_ROLE_KEY_TST }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_SITE_URL=${{ secrets.NEXT_PUBLIC_SITE_URL_TST }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_LOGFLARE_API_TOKEN=${{ secrets.NEXT_PUBLIC_LOGFLARE_API_TOKEN_TST }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_LOGFLARE_CLIENT_TOKEN=${{ secrets.NEXT_PUBLIC_LOGFLARE_CLIENT_TOKEN_TST }}" >> $GITHUB_ENV
fi
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/${{ env.REPOSITORY_NAME }}-${{ env.BRANCH_NAME }}:latest
build-args: |
NEXT_PUBLIC_SUPABASE_URL=${{ env.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY=${{ env.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
SUPABASE_SERVICE_ROLE_KEY=${{ env.SUPABASE_SERVICE_ROLE_KEY }}
NEXT_PUBLIC_SITE_URL=${{ env.NEXT_PUBLIC_SITE_URL }}
NEXT_PUBLIC_LOGFLARE_API_TOKEN=${{ env.NEXT_PUBLIC_LOGFLARE_API_TOKEN }}
NEXT_PUBLIC_LOGFLARE_CLIENT_TOKEN=${{ env.NEXT_PUBLIC_LOGFLARE_CLIENT_TOKEN }}
SMTP_HOST=${{ secrets.SMTP_HOST }}
SMTP_PORT=${{ secrets.SMTP_PORT }}
SMTP_USER=${{ secrets.SMTP_USER }}
SMTP_PASSWORD=${{ secrets.SMTP_PASSWORD }}