Skip to content

Commit dae2670

Browse files
committed
chore[deploy]: main 브랜치 배포
1 parent 36b375e commit dae2670

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: deploy
2+
on:
3+
push:
4+
paths:
5+
- '.github/workflows/**'
6+
- 'src/**'
7+
- 'build.gradle.kts'
8+
- 'settings.gradle.kts'
9+
- 'Dockerfile'
10+
branches:
11+
- main
12+
jobs:
13+
makeTagAndRelease:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
tag_name: ${{ steps.create_tag.outputs.new_tag }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Create Tag
20+
id: create_tag
21+
uses: mathieudutour/[email protected]
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
- name: Create Release
25+
id: create_release
26+
uses: actions/create-release@v1
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
tag_name: ${{ steps.create_tag.outputs.new_tag }}
31+
release_name: Release ${{ steps.create_tag.outputs.new_tag }}
32+
body: ${{ steps.create_tag.outputs.changelog }}
33+
draft: false
34+
prerelease: false
35+
buildImageAndPush:
36+
name: 도커 이미지 빌드와 푸시
37+
needs: makeTagAndRelease
38+
runs-on: ubuntu-latest
39+
env:
40+
DOCKER_IMAGE_NAME: balaw
41+
outputs:
42+
DOCKER_IMAGE_NAME: ${{ env.DOCKER_IMAGE_NAME }}
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: application-secret.yml 생성
46+
env:
47+
APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET_YML }}
48+
run: echo "$APPLICATION_SECRET" > src/main/resources/application-secret.yml
49+
- name: Docker Buildx 설치
50+
uses: docker/setup-buildx-action@v2
51+
- name: 레지스트리 로그인
52+
uses: docker/login-action@v2
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
- name: set lower case owner name
58+
run: |
59+
echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV}
60+
env:
61+
OWNER: '${{ github.repository_owner }}'
62+
- name: 빌드 앤 푸시
63+
uses: docker/build-push-action@v3
64+
with:
65+
context: .
66+
push: true
67+
tags: |
68+
ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.makeTagAndRelease.outputs.tag_name }},
69+
ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:latest
70+
71+
deploy:
72+
runs-on: ubuntu-latest
73+
needs: [ buildImageAndPush ]
74+
env:
75+
DOCKER_IMAGE_NAME: ${{ needs.buildImageAndPush.outputs.DOCKER_IMAGE_NAME }}
76+
steps:
77+
- name: AWS SSM Send-Command
78+
uses: peterkimzz/aws-ssm-send-command@master
79+
id: ssm
80+
with:
81+
aws-region: ${{ secrets.AWS_REGION }}
82+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
83+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
84+
instance-ids: "i-0b903187bca01a1c4"
85+
working-directory: /
86+
comment: Deploy
87+
command: |
88+
docker pull ghcr.io/doohyojeong/${{ env.DOCKER_IMAGE_NAME }}:latest
89+
docker stop app1 2>/dev/null
90+
docker rm app1 2>/dev/null
91+
docker run -d --name app1 -p 8080:8080 ghcr.io/doohyojeong/${{ env.DOCKER_IMAGE_NAME }}:latest
92+
docker rmi $(docker images -f "dangling=true" -q)

0 commit comments

Comments
 (0)