-
Notifications
You must be signed in to change notification settings - Fork 2
79 lines (68 loc) · 2.48 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: auto deploy with NCP Registry
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
checks: write
jobs:
push_to_registry:
name: Push to NCP Container Registry
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to NCP Container Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
- name: Get current timestamp
id: timestamp
run: echo "::set-output name=timestamp::$(date +%Y%m%d%H%M%S)"
- name: Build and Push Docker Image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/rehab-server:${{ steps.timestamp.outputs.timestamp }}
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/rehab-server:${{ steps.timestamp.outputs.timestamp }}
cache-to: type=inline
secrets: |
GIT_AUTH_TOKEN=${{ secrets.GIT_TOKEN }}
pull_from_registry:
name: Connect to Server and Pull from Container Registry
runs-on: ubuntu-latest
needs: push_to_registry
steps:
- name: Connect via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.NCP_SERVER_IP }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
port: ${{ secrets.NCP_SERVER_PORT }}
script: |
docker login -u ${{ secrets.NCP_ACCESS_KEY }} -p ${{ secrets.NCP_SECRET_KEY }} ${{ secrets.NCP_CONTAINER_REGISTRY }}
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/rehab-server:${{ steps.timestamp.outputs.timestamp }}
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker run -d -p 443:443 ${{ secrets.NCP_CONTAINER_REGISTRY }}/rehab-server:${{ steps.timestamp.outputs.timestamp }}
docker image prune -f