fest : link dependency #32
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: wheretobin-cicd | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
env: | |
REGION: asia-southeast1 | |
GAR_LOCATION: asia-southeast1-docker.pkg.dev/personal-388003/demo-registry-gar | |
jobs: | |
# ============== | |
# CI task | |
# ============== | |
build-and-push-image: | |
environment: dev | |
name: Build Docker image and push to repositories | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
module: | |
[ | |
backend, | |
frontend | |
] | |
steps: | |
- name: "Checkout" | |
uses: "actions/checkout@v3" | |
- name: Add image tags | |
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV | |
- id: "auth" | |
uses: "google-github-actions/auth@v2" | |
with: | |
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}" | |
- name: "Set up Cloud SDK" | |
uses: "google-github-actions/setup-gcloud@v2" | |
- name: "Use gcloud CLI" | |
run: "gcloud info" | |
- name: "Docker auth" | |
run: |- | |
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet | |
- name: Build image | |
run: docker build -f Dockerfile -t ${{ env.GAR_LOCATION }}/${{ matrix.module }}:${{ env.SHORT_SHA }} . | |
working-directory: ${{ matrix.module }} | |
- name: Push image | |
run: docker push ${{ env.GAR_LOCATION }}/${{ matrix.module }}:${{ env.SHORT_SHA }} | |
deploy: | |
environment: dev | |
needs: | |
- build-and-push-image | |
name: Deploy with Terraform | |
runs-on: ubuntu-latest | |
container: | |
image: alpine/terragrunt | |
steps: | |
- name: "Checkout" | |
uses: "actions/checkout@v3" | |
- name: Update dependencies | |
run: apk update && apk add --no-cache make | |
- name: "Run Terragrunt" | |
working-directory: "terraform" | |
env: | |
GOOGLE_CREDENTIALS: ${{ secrets.SERVICE_ACCOUNT_KEY }} | |
IMAGE_TAG: 1234 | |
run: |- | |
make plan ENV=dev | |
make apply ENV=dev |