-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (45 loc) · 2.1 KB
/
gradle.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
name: Build and Deploy
on:
push:
branches: [ develop ]
jobs:
build-and-deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'corretto'
- name: Create application.properties
run: |
echo "${{ secrets.FIREBASE }}" > src/main/resources/firebase.json
echo "${{ secrets.APPLICATION_TEST }}" > src/main/resources/application-test.properties
echo "${{ secrets.APPLICATION_LOCAL }}" > src/main/resources/application-local.properties
echo "${{ secrets.APPLICATION_DEV }}" > src/main/resources/application-dev.properties
- name: Build with Maven
run: mvn -e clean package -DskipTests
- name: Docker build and push
run: |
sudo docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }} .
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: |
# Stop and remove the existing container
sudo docker stop ${{ secrets.DOCKER_CONTAINER_NAME }}
sudo docker rm ${{ secrets.DOCKER_CONTAINER_NAME }}
# Remove the existing image
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}
# Login
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# Pull and run the application container
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_CONTAINER_NAME }}
sudo docker run -d -p 8080:8080 --name ${{ secrets.DOCKER_CONTAINER_NAME }} ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}