-
Notifications
You must be signed in to change notification settings - Fork 1
69 lines (59 loc) · 1.87 KB
/
Copy pathdeploy.yml
File metadata and controls
69 lines (59 loc) · 1.87 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
name: Docker CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker image
run: docker build -t slay1379/localens:latest -t slay1379/localens:${{ github.sha }} .
- name: Push Docker image
run: |
docker push slay1379/localens:latest
docker push slay1379/localens:${{ github.sha }}
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@v0.1.5
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ec2-user
key: ${{ secrets.AWS_SSH_KEY }}
script: |
docker pull slay1379/localens:${{ github.sha }}
docker stop localens || true
docker rm localens || true
docker run -d \
-p 8080:8080 \
-e SPRING_PROFILES_ACTIVE=prod \
--name localens \
--restart unless-stopped \
slay1379/localens:${{ github.sha }}
docker system prune -f