Skip to content

Commit fe1c366

Browse files
authored
chore: ci/cd를 위한 main.yml 추가 (#48)
1 parent 74ebc0d commit fe1c366

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

.github/workflows/main.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI/CD Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- 'client/release/*'
7+
8+
env:
9+
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/nest-openlist-deploy
10+
VERSION: ${{ github.sha }}
11+
NAME: go_cicd
12+
13+
jobs:
14+
build:
15+
name: Build
16+
runs-on: ubuntu-latest
17+
steps:
18+
# github repository에서 checkout
19+
- name: Check out source code
20+
uses: actions/checkout@v2
21+
# docker build 수행
22+
- name: Set up docker buildx
23+
id: buildx
24+
uses: docker/setup-buildx-action@v1
25+
- name: Cache docker layers
26+
uses: actions/cache@v2
27+
with:
28+
path: /tmp/.buildx-cache
29+
key: ${{ runner.os }}-buildx-${{ env.VERSION }} # runner 설정에서 읽어들일거에요.
30+
restore-keys: |
31+
${{ runner.os }}-buildx-
32+
# GitHub 컨테이너 레지스트리에 로그인 후 빌드 & 푸시
33+
- name: Login to ghcr
34+
uses: docker/login-action@v1
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GHCR_TOKEN }}
39+
- name: Build and push
40+
id: docker_build
41+
uses: docker/build-push-action@v2
42+
with:
43+
builder: ${{ steps.buildx.outputs.name }}
44+
push: true
45+
tags: ${{ env.DOCKER_IMAGE }}:latest
46+
# 배포 Job
47+
deploy:
48+
needs: build # build 후에 실행되도록 정의
49+
name: Deploy
50+
runs-on: [ self-hosted, label-go ] # ncloud ./configure에서 사용할 label명
51+
steps:
52+
- name: Login to ghcr
53+
uses: docker/login-action@v1
54+
with:
55+
registry: ghcr.io
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GHCR_TOKEN }}
58+
# 3000 -> 80 포트로 수행하도록 지정
59+
- name: Docker run
60+
run: |
61+
docker stop ${{ env.NAME }} && docker rm ${{ env.NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}:latest
62+
docker run -d -p 8080:5000 --name go_cicd --restart always ${{ env.DOCKER_IMAGE }}:latest

0 commit comments

Comments
 (0)