-
Notifications
You must be signed in to change notification settings - Fork 2
62 lines (51 loc) · 1.48 KB
/
backend_cd.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
name: Backend CD
on:
workflow_dispatch:
pull_request:
branches:
- develop
paths:
- backend/**
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Gradle
run: ./gradlew clean bootJar
- name: DockerHub Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker Build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest .
- name: Docker Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest
deploy:
runs-on: self-hosted
needs: build
defaults:
run:
working-directory: backend
steps:
- name: Docker Pull & Run
run: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest
docker stop server || true
docker container prune -f
docker run -d --name server -p 8080:8080 \
--env-file ./.env \
${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest
docker rmi $(docker images -f "dangling=true" -q)