Build and Push Docker Image #13
This file contains 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: | |
- master | |
paths: | |
- 'apps/api/**' | |
workflow_dispatch: # Allows the workflow to be triggered manually | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Google Container Registry | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} | |
- name: Configure Docker for Google Container Registry | |
run: gcloud auth configure-docker asia-east2-docker.pkg.dev | |
- name: Extract version from package.json | |
id: extract_version | |
run: | | |
version=$(jq -r '.version' apps/api/package.json) | |
echo "VERSION=$version" >> $GITHUB_ENV | |
- name: Build Docker image | |
run: | | |
printf "%s" "${{ secrets.SERVICE_ACCOUNT_KEYFILE }}" > /tmp/service-account-keyfile.json | |
DOCKER_BUILDKIT=1 docker build \ | |
--secret id=service_account_keyfile,src=/tmp/service-account-keyfile.json \ | |
-f Dockerfile.api \ | |
-t asia-east2-docker.pkg.dev/maituongluan/dashboard/api:$VERSION . | |
rm /tmp/service-account-keyfile.json | |
- name: Push Docker image | |
run: | | |
docker push asia-east2-docker.pkg.dev/maituongluan/dashboard/api:$VERSION |