-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (79 loc) · 3.27 KB
/
cd-dev.yml
File metadata and controls
93 lines (79 loc) · 3.27 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: DEV) Push Docker Image And Deploy to EC2
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Set up yml ec2 dev file
env:
YAML_SECRET: ${{ secrets.YAML_EC2_DEV }}
YAML_DIR: src/main/resources
YAML_FILE_NAME: application-ec2-dev.yml
run: |
echo $YAML_SECRET | base64 --decode > $YAML_DIR/$YAML_FILE_NAME
echo "YAML_SECRET has been decoded and saved to $YAML_DIR/$YAML_FILE_NAME"
- name: Set up yml secrets file
env:
YAML_SECRET: ${{ secrets.YAML_SECRET }}
YAML_DIR: src/main/resources
YAML_FILE_NAME: application-secret.yml
run: |
echo $YAML_SECRET | base64 --decode > $YAML_DIR/$YAML_FILE_NAME
echo "YAML_SECRET has been decoded and saved to $YAML_DIR/$YAML_FILE_NAME"
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Get Short SHA
id: short_sha
run: |
echo "::set-output name=sha_short::$(echo ${{ github.sha }} | head -c 7)"
echo "Short SHA: ${{ steps.short_sha.outputs.sha_short }}"
- name: Print branch & tag information
run: |
echo "Current branch: ${{ github.event.inputs.branch || github.ref }}"
echo "Current tag: ${{ steps.short_sha.outputs.sha_short }}"
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker Login and Push
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
DOCKER_IMAGE_TAG: tech-log:${{ steps.short_sha.outputs.sha_short }}
run: |
echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
docker build -t $DOCKER_IMAGE_TAG .
docker tag $DOCKER_IMAGE_TAG $DOCKER_HUB_USERNAME/$DOCKER_IMAGE_TAG
docker push $DOCKER_HUB_USERNAME/$DOCKER_IMAGE_TAG
# Deploy to EC2
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_IP }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.EC2_PEM_KEY }}
script: |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/tech-log:${{ steps.short_sha.outputs.sha_short }}
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/tech-log:${{ steps.short_sha.outputs.sha_short }} tech-log
docker rm -f tech-log || true
docker run -d --name tech-log -e TZ=Asia/Seoul -e SPRING_PROFILES_ACTIVE=ec2-dev -p 8081:8081 ${{ secrets.DOCKER_HUB_USERNAME }}/tech-log:${{ steps.short_sha.outputs.sha_short }}