-
Notifications
You must be signed in to change notification settings - Fork 1
60 lines (50 loc) · 1.71 KB
/
CD.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: CD
on:
push:
branches:
- main
permissions:
contents: read
jobs:
cd:
runs-on: ubuntu-22.04
env:
IMAGE_TAG: ${{ github.sha }}
REPO: ${{ secrets.DOCKER_REPOSITORY }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'gradle'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Execute Gradle build
run: ./gradlew clean :bootBuildImage --imageName=$REPO:$IMAGE_TAG
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Publish Docker image
run: |
echo "Pushing Docker image with tag: $IMAGE_TAG"
docker push $REPO:$IMAGE_TAG
- name: Send command by AWS SSM
uses: peterkimzz/aws-ssm-send-command@master
id: ssm
with:
aws-region: ap-northeast-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
instance-ids: ${{ secrets.AWS_INSTANCE_ID }}
working-directory: ${{ vars.DEPLOY_SCRIPT_PATH }}
command: |
echo "############# PULL DOCKER IMAGE #############"
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker pull ${{ env.REPO }}:${{ env.IMAGE_TAG }}
echo "############# RUN DEPLOY SCRIPT #############"
sh scripts/deploy.sh ${{ env.REPO }} ${{ env.IMAGE_TAG }}