Skip to content

Commit ad64cdb

Browse files
authored
Merge pull request #29 from POPCONG/develop
[Deploy] 1차 배포 (수정 3차)
2 parents d9f4259 + d04bc03 commit ad64cdb

1 file changed

Lines changed: 26 additions & 40 deletions

File tree

.github/workflows/release-deploy.yml

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,50 @@ jobs:
2121
permissions:
2222
id-token: write
2323
contents: read
24-
25-
outputs:
26-
registry: ${{ steps.meta.outputs.registry }}
27-
image_tag: ${{ steps.meta.outputs.image_tag }}
28-
2924
steps:
30-
- name: Checkout
31-
uses: actions/checkout@v4
32-
33-
- name: Configure AWS credentials
34-
uses: aws-actions/configure-aws-credentials@v4
25+
- uses: actions/checkout@v4
26+
- uses: aws-actions/configure-aws-credentials@v4
3527
with:
3628
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
3729
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3830
aws-region: ${{ env.AWS_REGION }}
39-
40-
- name: Compute dynamic env (REGISTRY, IMAGE_TAG)
41-
id: meta
42-
run: |
43-
echo "REGISTRY=${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" >> "$GITHUB_ENV"
44-
echo "IMAGE_TAG=${GITHUB_SHA}" >> "$GITHUB_ENV"
45-
echo "registry=${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" >> "$GITHUB_OUTPUT"
46-
echo "image_tag=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
47-
48-
- name: Login to Amazon ECR
49-
uses: aws-actions/amazon-ecr-login@v2
50-
51-
- name: Set up Docker Buildx
52-
uses: docker/setup-buildx-action@v3
53-
54-
- name: Build & Push (linux/amd64)
55-
uses: docker/build-push-action@v6
31+
- uses: aws-actions/amazon-ecr-login@v2
32+
- uses: docker/setup-buildx-action@v3
33+
- uses: docker/build-push-action@v6
5634
with:
5735
platforms: linux/amd64
5836
push: true
5937
context: .
6038
file: ./Dockerfile
6139
tags: |
62-
${{ env.REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
63-
${{ env.REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest
40+
${{ env.ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
41+
${{ env.ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:latest
6442
6543
deploy:
6644
if: github.ref == 'refs/heads/release'
6745
needs: build-and-push
6846
runs-on: ubuntu-latest
6947
timeout-minutes: 15
70-
7148
steps:
72-
- name: Connect & Deploy on EC2
73-
uses: appleboy/[email protected]
74-
with:
75-
host: ${{ secrets.EC2_HOST }}
76-
username: ${{ secrets.EC2_USER }}
77-
key: ${{ secrets.EC2_SSH_KEY }}
78-
script: |
49+
- name: 복호화하여 SSH 키 파일 생성
50+
shell: bash
51+
run: |
52+
echo "${{ secrets.EC2_SSH_KEY_B64 }}" | base64 -d > key.pem
53+
chmod 600 key.pem
54+
55+
- name: EC2에 접속해 배포 실행
56+
shell: bash
57+
env:
58+
AWS_REGION: ${{ env.AWS_REGION }}
59+
ACCOUNT_ID: ${{ env.ACCOUNT_ID }}
60+
ECR_REPO: ${{ env.ECR_REPOSITORY }}
61+
run: |
62+
ssh -o StrictHostKeyChecking=no -i key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOSSH'
7963
set -euo pipefail
80-
AWS_REGION="${{ env.AWS_REGION }}"
81-
ACCOUNT_ID="${{ env.ACCOUNT_ID }}"
64+
AWS_REGION="${AWS_REGION}"
65+
ACCOUNT_ID="${ACCOUNT_ID}"
8266
REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
67+
REPO="${ECR_REPO}"
8368
8469
echo "[EC2] ECR 로그인"
8570
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$REGISTRY"
@@ -95,4 +80,5 @@ jobs:
9580
9681
echo "[EC2] 상태 확인"
9782
docker compose ps
98-
docker ps
83+
docker ps
84+
EOSSH

0 commit comments

Comments
 (0)