-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (41 loc) · 1.3 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
name: CD
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'zulu'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew --build-cache build
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ secrets.DOCKER_HUB }}:latest
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push the Docker image
run: docker push ${{ secrets.DOCKER_HUB }}:latest
- name: Connect EC2 & Deploy Docker Image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
port: ${{ secrets.EC2_PORT }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
script: |
cd kodomo
docker pull ${{ secrets.DOCKER_HUB }}:latest
docker rm -f jugan-server
docker image prune -a -f
docker run --name jugan-server -dp 8080:8080 --env-file .env ${{ secrets.DOCKER_HUB }}:latest