Skip to content

Commit

Permalink
update: productioin.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
siwonpada committed Jun 16, 2024
1 parent 15f185b commit 5520377
Showing 1 changed file with 58 additions and 30 deletions.
88 changes: 58 additions & 30 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,71 @@ on:

jobs:
build:
uses: gsainfoteam/infoteam-actions/.github/workflows/default-docker-build.yml@master
with:
repo_name: ziggle-backend
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

deploy:
name: Deploy
name: Build docker Image
runs-on: ubuntu-latest
needs:
- build
outputs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ziggle-backend
IMAGE_TAG: prod${{ github.run_number }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
mask-aws-account-id: no

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build, tag, and push image to Amazon ECR
uses: docker/build-push-action@v2
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ziggle-backend
IMAGE_TAG: prod${{ github.run_number }} # Use run number as image tag
with:
context: .
push: true
tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

deploy:
name: Update Git Repository
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
repository: gsainfoteam/infoteam-infra
repository: gsainfoteam/icarus-gitops
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
fetch-depth: 0

- name: Set version ENV, and commit
- name: Update Kubernetes Manifest
env:
ECR_REGISTRY: ${{ needs.build.outputs.ECR_REGISTRY }}
ECR_REPOSITORY: ${{ needs.build.outputs.ECR_REPOSITORY }}
IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }}
run: |
VERSIONS_FILE_PATH=apps/mail/ziggle-backend-prod/versions.env
source $VERSIONS_FILE_PATH
BACKEND_TAG="${GITHUB_REF_NAME}_${GITHUB_SHA}"
cat <<EOF > $VERSIONS_FILE_PATH
BACKEND_TAG="${BACKEND_TAG}"
EOF
git config --local user.email "[email protected]"
git config --local user.name "Github-Actions[bot] @ gsainfoteam/ziggle_be"
git commit -a -m "mail/ziggle-backend-prod: update version.env to ${GITHUB_SHA::7}"
- name: Push to infoteam-infra
uses: ad-m/github-push-action@master
with:
ssh: true
repository: gsainfoteam/infoteam-infra
branch: master
sed -i "s|image:.*|image: $ECR_REGISTRY\/$ECR_REPOSITORY:$IMAGE_TAG|g" infoteam/service/ziggle/prod.yaml
- name: Commit and Push
env:
ECR_REPOSITORY: ${{ needs.build.outputs.ECR_REPOSITORY }}
IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }}
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
git commit -am "Update image $ECR_REPOSITORY:$IMAGE_TAG"
git push -u origin master

0 comments on commit 5520377

Please sign in to comment.