Skip to content

Commit

Permalink
refactor: image push workflows 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
GIVEN53 committed Feb 7, 2024
1 parent 2660917 commit 4e3fa6c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 48 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/aws-config.yml

This file was deleted.

44 changes: 20 additions & 24 deletions .github/workflows/deploy-fluentbit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- '.github/workflows/**'

env:
ECR_URI: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com
ENDPOINT: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com
DEV_REPO: ${{ secrets.DEV_FLUENTBIT_ECR_REPOSITORY }}
PROD_REPO: ${{ secrets.PROD_FLUENTBIT_ECR_REPOSITORY }}
TASK_DEFINITION: ${{ secrets.TASK_DEFINITION_NAME }}-prod
Expand All @@ -21,17 +21,15 @@ env:
jobs:
deploy-dev:
runs-on: ubuntu-latest
env:
working-directory: ./fluentbit
steps:
- name: Configure aws
uses: ./.github/workflows/aws-config.yml
- name: Check out code
uses: actions/checkout@v3

- name: Build and push image to Amazon ECR
run: |
docker build -t ${{ env.ECR_URI }}/${{ env.DEV_REPO }}:${{ env.TAG }} .
docker push ${{ env.ECR_URI }}/${{ env.DEV_REPO }}:${{ env.TAG }}
working-directory: ${{ env.working-directory }}
- name: Push image to Amazon ECR
uses: ./.github/workflows/push-image.yml
with:
uri: ${{ env.ENDPOINT }}/${{ env.DEV_REPO }}:${{ env.TAG }}
working-directory: ./fluentbit

- name: Pull image from Amazon ECR and restart container in EC2
uses: appleboy/ssh-action@master
Expand All @@ -40,24 +38,22 @@ jobs:
host: ${{ secrets.DEV_SERVER_HOST }}
username: ${{ secrets.DEV_SERVER_USER }}
script: |
docker login -u AWS -p $(aws ecr get-login-password --region ap-northeast-2) ${{ env.ECR_URI }}
docker pull ${{ env.ECR_URI }}/${{ env.DEV_REPO }}:${{ env.TAG }}
docker login -u AWS -p $(aws ecr get-login-password --region ap-northeast-2) ${{ env.ENDPOINT }}
docker pull ${{ env.ENDPOINT }}/${{ env.DEV_REPO }}:${{ env.TAG }}
docker stop fluentbit-dev && docker rm fluentbit-dev
docker run -d --name fluentbit-dev -p 8888:8888 --network dev-network -e env=dev ${{ env.ECR_URI }}/${{ env.DEV_REPO }}:${{ env.TAG }}
docker run -d --name fluentbit-dev -p 8888:8888 --network dev-network -e env=dev ${{ env.ENDPOINT }}/${{ env.DEV_REPO }}:${{ env.TAG }}
deploy-prod:
runs-on: ubuntu-latest
env:
working-directory: ./fluentbit
steps:
- name: Configure aws
uses: ./.github/workflows/aws-config.yml
- name: Check out code
uses: actions/checkout@v3

- name: Build and push image to Amazon ECR
run: |
docker build -t ${{ env.ECR_URI }}/${{ env.PROD_REPO }}:${{ env.TAG }} .
docker push ${{ env.ECR_URI }}/${{ env.PROD_REPO }}:${{ env.TAG }}
working-directory: ${{ env.working-directory }}
- name: Push image to Amazon ECR
uses: ./.github/workflows/push-image.yml
with:
uri: ${{ env.ENDPOINT }}/${{ env.PROD_REPO }}:${{ env.TAG }}
working-directory: ./fluentbit

- name: Download task definition
run: |
Expand All @@ -69,7 +65,7 @@ jobs:
with:
task-definition: task-definition.json
container-name: ${{ env.ECS_CONTAINER }}
image: ${{ env.ECR_URI }}/${{ env.PROD_REPO }}:${{ env.TAG }}
image: ${{ env.ENDPOINT }}/${{ env.PROD_REPO }}:${{ env.TAG }}

- name: Deploy Amazon ECS task definition
id: deploy
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: AWS ECR Login and Push Image

on:
workflow_call:
inputs:
uri:
description: 'URI of the repository'
required: true
type: string
working-directory:
description: 'Working directory'
required: true
type: string


jobs:
push-image:
runs-on: ubuntu-latest
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'

- name: Build and push image to Amazon ECR
run: |
docker build -t ${{ inputs.uri}} .
docker push ${{ inputs.uri}}
working-directory: ${{ inputs.working-directory }}

0 comments on commit 4e3fa6c

Please sign in to comment.