fest yarn onlt #35
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 | |
# ============== | |
unit-test: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
checks: write | |
statuses: write | |
steps: | |
- name: "Checkout" | |
uses: "actions/checkout@v3" | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Install modules | |
working-directory: frontend | |
run: yarn install | |
- name: Run unit test | |
working-directory: frontend | |
run: yarn test | |
build-and-push-image: | |
environment: dev | |
needs: | |
- unit-test | |
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: ${{ env.SHORT_SHA }} | |
run: |- | |
export IMAGE_TAG=${IMAGE_TAG} | |
make plan ENV=dev | |
make apply ENV=dev |