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 # main 브랜치로 머지되면 실행
12+
13+ jobs :
14+ makeTagAndRelease :
15+ runs-on : ubuntu-latest
16+ outputs :
17+ tag_name : ${{ steps.create_tag.outputs.new_tag }}
18+ steps :
19+ - uses : actions/checkout@v4
20+ - name : Create Tag
21+ id : create_tag
22+ uses :
mathieudutour/[email protected] 23+ with :
24+ github_token : ${{ secrets.GITHUB_TOKEN }}
25+
26+ - name : Create Release
27+ id : create_release
28+ uses : actions/create-release@v1
29+ env :
30+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
31+ with :
32+ tag_name : ${{ steps.create_tag.outputs.new_tag }}
33+ release_name : Release ${{ steps.create_tag.outputs.new_tag }}
34+ body : ${{ steps.create_tag.outputs.changelog }}
35+ draft : false
36+ prerelease : false
37+
38+ buildImageAndPush :
39+ name : 도커 이미지 빌드와 푸시
40+ needs : makeTagAndRelease
41+ runs-on : ubuntu-latest
42+ env :
43+ DOCKER_IMAGE_NAME : catfe-backend
44+ DOT_ENV : ${{ secrets.DOT_ENV }}
45+ OWNER : ${{ github.repository_owner }}
46+ steps :
47+ - uses : actions/checkout@v4
48+ - name : .env 생성
49+ run : echo "$DOT_ENV" > .env
50+
51+ - name : Docker Buildx 설치
52+ uses : docker/setup-buildx-action@v2
53+
54+ - name : 레지스트리 로그인
55+ uses : docker/login-action@v2
56+ with :
57+ registry : ghcr.io
58+ username : ${{ github.actor }}
59+ password : ${{ secrets.GITHUB_TOKEN }}
60+
61+ - name : set lower case owner name
62+ run : |
63+ echo "OWNER_LC=${{ toLower(env.OWNER) }}" >> ${GITHUB_ENV}
64+
65+
66+ - name : 빌드 앤 푸시
67+ uses : docker/build-push-action@v3
68+ with :
69+ context : .
70+ push : true
71+ tags : |
72+ ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.makeTagAndRelease.outputs.tag_name }},
73+ ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:latest
74+
75+
76+ deploy :
77+ runs-on : ubuntu-latest
78+ needs : [ buildImageAndPush ]
79+ steps :
80+ - name : AWS SSM Send-Command
81+ uses : peterkimzz/aws-ssm-send-command@master
82+ id : ssm
83+ with :
84+ aws-region : ${{ secrets.AWS_REGION }}
85+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
86+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
87+ instance-ids : " i-00e384163ab61f6cc"
88+ working-directory : /
89+ comment : Deploy
90+ command : |
91+ docker pull ghcr.io/${{ env.OWNER_LC }}/catfe-backend:latest
92+ docker stop catfe-backend 2>/dev/null
93+ docker rm catfe-backend 2>/dev/null
94+ docker run -d --name catfe-backend -p 8080:8080 ghcr.io/${{ env.OWNER_LC }}/catfe-backend:latest
0 commit comments