Merge pull request #80 from afifurrohman-id/dependabot/go_modules/goo… #100
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: Ci Cd Production Environment | |
on: | |
push: | |
branches: main | |
jobs: | |
test: | |
environment: | |
name: production | |
runs-on: ubuntu-latest | |
# because we cannot use env directly when using docker run | |
env: | |
GOOGLE_CLOUD_STORAGE_SERVICE_ACCOUNT: ${{secrets.GOOGLE_CLOUD_STORAGE_SERVICE_ACCOUNT}} | |
GOOGLE_CLOUD_STORAGE_BUCKET: ${{secrets.GOOGLE_CLOUD_STORAGE_BUCKET}} | |
SERVER_URL: ${{secrets.SERVER_URL}} | |
GOOGLE_OAUTH2_REFRESH_TOKEN_TEST: ${{secrets.GOOGLE_OAUTH2_REFRESH_TOKEN_TEST}} | |
APP_ENV: ${{secrets.APP_ENV}} | |
GOOGLE_OAUTH2_CLIENT_ID_TEST: ${{secrets.GOOGLE_OAUTH2_CLIENT_ID_TEST}} | |
GOOGLE_OAUTH2_CLIENT_SECRET_TEST: ${{secrets.GOOGLE_OAUTH2_CLIENT_SECRET_TEST}} | |
PORT: ${{secrets.PORT}} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: jbergstroem/hadolint-gh-action@v1 | |
with: | |
dockerfile: build/package/**Containerfile | |
# Setup new docker builder for cache | |
- uses: docker/setup-buildx-action@v3 | |
- name: Build Image Test | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
load: true | |
file: build/package/test.Containerfile | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: ${{github.event.repository.name}} | |
- name: Unit testing # Using staging environment | |
run: | | |
docker run --rm \ | |
--name ${{github.event.repository.owner.login}} \ | |
-e GOOGLE_CLOUD_STORAGE_SERVICE_ACCOUNT -e GOOGLE_CLOUD_STORAGE_BUCKET \ | |
-e SERVER_URL -e GOOGLE_OAUTH2_REFRESH_TOKEN_TEST \ | |
-e APP_ENV -e PORT \ | |
-e GOOGLE_OAUTH2_CLIENT_ID_TEST -e GOOGLE_OAUTH2_CLIENT_SECRET_TEST \ | |
${{github.event.repository.name}} \ | |
go test --cover -v \ | |
-ldflags "-w -s" ./... | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
environment: | |
name: production | |
url: ${{github.event.repository.homepage}} | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ghcr.io/${{github.repository}} | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
# Setup new docker builder and qemu for multi arch build | |
- uses: docker/setup-qemu-action@v3 | |
- uses: docker/setup-buildx-action@v3 | |
- uses: docker/login-action@v3 | |
with: | |
registry: ${{env.REGISTRY}} | |
username: ${{github.repository_owner}} | |
password: ${{secrets.GITHUB_TOKEN}} | |
- uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: build/package/Containerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
${{env.IMAGE_NAME}}:${{github.sha}} | |
${{env.IMAGE_NAME}} | |
- uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- uses: azure/container-apps-deploy-action@v2 | |
with: | |
registryUrl: ${{env.REGISTRY}} | |
containerAppName: ${{github.event.repository.name}} | |
resourceGroup: ${{secrets.AZURE_RESOURCE_GROUP}} | |
imageToDeploy: ${{env.IMAGE_NAME}}:${{github.sha}} | |
targetPort: ${{secrets.PORT}} | |
ingress: internal | |
- name: Job Successful Feedback | |
if: ${{ success() }} | |
run: | | |
cat >> $GITHUB_STEP_SUMMARY <<MD | |
# Successful CI & CD production environment | |
**This test include:** | |
- [x] Tidy | |
- [x] Formatting | |
- [x] Unit Test | |
**App Published to:** ${{github.event.repository.homepage}} | |
MD |