-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (45 loc) · 1.86 KB
/
backend-publish.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
name: CI/CD using GitHub Actions & Docker
on:
push:
branches: [ "main" ]
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: Create directory and file if not exist
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application-prod.yml
echo "cors:" >> ./src/main/resources/application-prod.yml
echo " allowed-origin: ${{ secrets.ALLOWED_ORIGIN }}" >> ./src/main/resources/application-prod.yml
echo " max-age: 2400" >> ./src/main/resources/application-prod.yml
- name: Set executable permission
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker build & push to prod
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT .
docker push ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT
- name: Deploy to prod
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker stop spaced || true
sudo docker rm spaced || true
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT
sudo docker run -d -p 8080:8080 --name spaced ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT \
--spring.profiles.active=prod