chore: refactor monorepo #12
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: Deploy | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
# build: | |
# name: Build | |
# runs-on: ubuntu-latest | |
# permissions: | |
# id-token: write | |
# contents: read | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# - name: Set up Node.js | |
# uses: actions/setup-node@v4 | |
# with: | |
# node-version: '20' | |
# - run: pnpm build | |
# - run: pnpm test | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ap-southeast-2 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push docker image to Amazon ECR | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: my-ecr-repo | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t $ECR_REPOSITORY:${{ github.sha }} . | |
docker tag $ECR_REPOSITORY:${{ github.sha }} $ECR_REPOSITORY:latest | |
docker push $ECR_REPOSITORY:${{ github.sha }} | |
docker push $ECR_REPOSITORY:latest | |
- name: Set IMAGE_TAG | |
run: echo "IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v3 | |
- name: Terraform Format Check | |
run: terraform fmt -check | |
continue-on-error: true | |
- name: Initialize Terraform | |
run: terraform init | |
- name: Terraform Validate | |
run: terraform validate | |
- name: Terraform Plan | |
id: plan | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: terraform plan -no-color -out=tfplan -var="DATABASE_URL=${{ secrets.DATABASE_URL }}" | |
- name: Terraform Apply | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: terraform apply -auto-approve tfplan |