-
Notifications
You must be signed in to change notification settings - Fork 2
88 lines (74 loc) · 2.51 KB
/
develop_build_deploy.yml
File metadata and controls
88 lines (74 loc) · 2.51 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
name: Build and Deploy to Develop
on:
push:
branches:
- develop
env:
DOCKERHUB_USERNAME: ht3064
DOCKERHUB_IMAGE_NAME: devfit-server
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Start Redis container for test
run: docker compose -f ./docker-compose-test.yml up -d
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Extract metadata for Docker
id: metadata
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}
tags: |
type=sha,prefix=
- name: Build and Push Docker image
uses: docker/build-push-action@v4.1.1
with:
context: .
push: true
tags: ${{ steps.metadata.outputs.tags }}
- name: Copy docker-compose.yml to EC2
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: docker-compose.yml
target: /home/ubuntu/
- name: Copy default.conf to EC2
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: nginx/default.conf
target: /home/ubuntu/
- name: Deploy to EC2
uses: appleboy/ssh-action@master
env:
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }}
DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }}
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME
script: |
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin
docker compose up -d
docker exec nginx nginx -s reload
docker image prune -a -f