-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (83 loc) · 3.07 KB
/
docker-ncp-build.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
95
96
97
name: Docker Spring NCP
on:
push:
branches: ["feat/ncloud"]
jobs:
build_dockerpush:
runs-on: ubuntu-latest
steps:
- name: Create .application-real.yml
run: |
cat <<EOF > application-real.yml
spring:
datasource:
url: ${{ secrets.DB_URL }}
username: ${{ secrets.DB_USERNAME }}
password: ${{ secrets.DB_PASSWORD }}
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: create
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
default_schema: starpool
EOF
- name: Upload application-real.yml to Artifacts
uses: actions/upload-artifact@v2
with:
name: application-real
path: application-real.yml
- name: Download application-real.yml Artifact
uses: actions/download-artifact@v2
with:
name: application-real
path: ./src/main/resources
- name: Checkout
uses: actions/checkout@v2
- 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: build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/tag-name:latest
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/tag-name:latest
cache-to: type=inline
pull_deploy:
name: Connect server ssh and pull from container registry
needs: build_dockerpush
runs-on: ubuntu-latest
steps:
- name: connect ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
username: ${{ secrets.DEPLOYMENT_USERNAME }}
password: ${{ secrets.DEPLOYMENT_PASSWORD }}
port: ${{ secrets.DEPLOYMENT_PORT }}
script: |
docker login -u ${{ secrets.NCP_ACCESS_KEY }} -p ${{ secrets.NCP_SECRET_KEY }} ${{ secrets.NCP_CONTAINER_REGISTRY }}
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/tag-name
# 이미지 이름으로 실행 중인 컨테이너 ID를 찾기
CONTAINER_IDS=$(docker ps -q --filter label=app=spring)
# 찾은 컨테이너 종료
if [ ! -z "$CONTAINER_IDS" ]; then
docker stop $CONTAINER_IDS
fi
# 찾은 컨테이너 삭제
if [ ! -z "$CONTAINER_IDS" ]; then
docker rm $CONTAINER_IDS
fi
# 이미지 실행
docker run -d -p 8080:8080 --label app=spring ${{ secrets.NCP_CONTAINER_REGISTRY }}/tag-name
# 사용하지 않는 이미지 정리
docker image prune -f