Skip to content

Commit 69c6f21

Browse files
committed
cd: [KAN-148] multi env deploy
1 parent 2368dbf commit 69c6f21

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

.github/workflows/deploy.yml

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ name: Deploy Go to EC2 (manual)
33
on:
44
workflow_dispatch: # ← Manual trigger button
55
inputs:
6+
env_name:
7+
description: 'env_name'
8+
required: true
9+
default: 'dev'
10+
type: choice
11+
options:
12+
- prod
13+
- dev
614
version:
715
description: 'version'
816
required: false
@@ -16,7 +24,6 @@ on:
1624
options:
1725
- build
1826
- deploy
19-
- swarm-deploy
2027
- restart
2128
- rollback
2229

@@ -39,7 +46,7 @@ jobs:
3946
name: env-file
4047
path: env-file
4148
build:
42-
if: ${{ github.event.inputs.command == 'deploy' }} || ${{ github.event.inputs.command == 'build' }} || ${{ github.event.inputs.command == 'swarm-deploy' }}
49+
if: ${{ github.event.inputs.command == 'deploy' || github.event.inputs.command == 'build' }}
4350
runs-on: ubuntu-latest
4451
env:
4552
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -58,11 +65,12 @@ jobs:
5865
run: |
5966
docker push "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
6067
deploy:
61-
if: ${{ github.event.inputs.command == 'deploy' }}
68+
if: ${{ github.event.inputs.command == 'deploy' && github.event.inputs.env_name == 'dev' }}
6269
needs:
6370
- build
6471
- generate-env
65-
runs-on: self-hosted
72+
runs-on: [self-hosted, dev, docker]
73+
environment: dev
6674
env:
6775
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
6876
steps:
@@ -79,16 +87,37 @@ jobs:
7987
docker stop ceramicraft-user-mservice || true
8088
docker rm ceramicraft-user-mservice || true
8189
docker run -d --name ceramicraft-user-mservice --network ceramicraft-network -v /home/ubuntu/logs:/app/logs --env-file env-file "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
90+
swarm-deploy:
91+
if: ${{ github.event.inputs.command == 'deploy' && github.event.inputs.env_name == 'prod' }}
92+
runs-on: [self-hosted,prod,swarm]
93+
environment: prod
94+
needs: build
95+
env:
96+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
97+
steps:
98+
- name: pull the docker image
99+
run: |
100+
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
101+
- name: update the service
102+
run: |
103+
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
82104
restart:
83-
if: ${{ github.event.inputs.command == 'restart' }}
84-
runs-on: self-hosted
105+
if: ${{ github.event.inputs.command == 'restart' && github.event.inputs.env_name == 'dev' }}
106+
runs-on: [self-hosted,dev,docker]
85107
steps:
86108
- name: restart docker container
87109
run: |
88110
docker restart ceramicraft-user-mservice || true
111+
swarm_restart:
112+
if: ${{ github.event.inputs.command == 'restart' && github.event.inputs.env_name == 'prod' }}
113+
runs-on: [self-hosted,prod,swarm]
114+
steps:
115+
- name: restart the service
116+
run: |
117+
docker service update --force ms-stack_user-ms || true
89118
rollback:
90-
if: ${{ github.event.inputs.command == 'rollback' }}
91-
runs-on: self-hosted
119+
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'dev' }}
120+
runs-on: [self-hosted, dev, docker]
92121
needs: generate-env
93122
env:
94123
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -106,10 +135,9 @@ jobs:
106135
docker stop ceramicraft-user-mservice || true
107136
docker rm ceramicraft-user-mservice || true
108137
docker run -d --name ceramicraft-user-mservice --network ceramicraft-network -v /home/ubuntu/logs:/app/logs --env-file env-file "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
109-
swarm-deploy:
110-
if: ${{ github.event.inputs.command == 'swam-deploy' }}
111-
runs-on: self-hosted
112-
needs: build
138+
swarm-rollback:
139+
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'prod' }}
140+
runs-on: [self-hosted,prod,swarm]
113141
env:
114142
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
115143
steps:
@@ -118,4 +146,4 @@ jobs:
118146
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
119147
- name: update the service
120148
run: |
121-
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
149+
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true

0 commit comments

Comments
 (0)