-
Notifications
You must be signed in to change notification settings - Fork 4
64 lines (52 loc) · 2 KB
/
deploy.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
61
62
63
64
name: Java CI with Gradle Deploy
on:
push:
branches: [ "deploy" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Run chmod to make gradlew executable
run: chmod +x ./backend/gradlew
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Set environment values
run: |
cd ./backend/src/main/resources
touch ./env.properties
echo "${{ secrets.ENV }}" > ./env.properties
shell: bash
- name: Build with Gradle
run: |
cd ./backend
./gradlew clean build -x test
- name: Docker build and push
run: |
cd ./backend
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker build -t ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} .
docker buildx build --push --platform linux/amd64 -t ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} .
- name: Clean up dangling Docker images locally
run: |
sudo docker image prune -f
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRIVATE_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
echo ${{ secrets.DOCKERHUB_PASSWORD }} | sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
sudo docker pull ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7}
sudo docker tag ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} look-us
cd ./look-us
sudo docker-compose down
sudo docker compose up -d
# Clean up old Docker images on the server
sudo docker image prune -f