-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (81 loc) · 2.68 KB
/
ci.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: build & deploy
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '21'
- name: checkout
uses: actions/checkout@v2
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: build and test
run: mvn -B package --file pom.xml
deploy:
if: ${{ github.ref == 'refs/heads/master' }}
needs: [ build ]
runs-on: ubuntu-latest
concurrency: deployment
steps:
- name: Set up Java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '21'
- name: checkout
uses: actions/checkout@v2
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: build and publish image to dockerhub
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
run: |
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
echo GITHUB_REF - $ref
mvn -B spring-boot:build-image -DskipTests
docker tag donfaq/ruchi:latest donfaq/ruchi:${ref}
docker push -aq donfaq/ruchi
- name: ssh-to-server
uses: appleboy/ssh-action@master
env:
GIT_REPO: ${{ github.repository }}
GIT_REPO_NAME: ${{ github.event.repository.name }}
GIT_SHA: ${{ github.sha }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
envs: GIT_REPO,GIT_SHA,GIT_REPO_NAME
script: |
rm -rf ~/projects/$GIT_REPO_NAME
cd ~/projects
git clone git@github.com:$GIT_REPO.git
cd ~/projects/$GIT_REPO_NAME
git checkout -q -d $GIT_SHA
cp ~/projects/$GIT_REPO_NAME.env ./.env
docker-compose down --remove-orphans
docker system prune -f -a --volumes
docker-compose pull -q
docker-compose up --detach --no-color --quiet-pull --force-recreate --renew-anon-volumes --remove-orphans