Skip to content

Commit 82985c4

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

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

.github/workflows/deploy.yml

Lines changed: 41 additions & 15 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,16 +24,13 @@ on:
1624
options:
1725
- build
1826
- deploy
19-
- swarm-deploy
2027
- restart
2128
- rollback
2229

2330
jobs:
2431
generate-env:
2532
name: Generate .env file
2633
runs-on: ubuntu-latest
27-
outputs:
28-
env-path: ${{ steps.set-output.outputs.env-path }}
2934
steps:
3035
- name: Generate .env file
3136
run: |
@@ -39,7 +44,7 @@ jobs:
3944
name: env-file
4045
path: env-file
4146
build:
42-
if: ${{ github.event.inputs.command == 'deploy' }} || ${{ github.event.inputs.command == 'build' }} || ${{ github.event.inputs.command == 'swarm-deploy' }}
47+
if: ${{ github.event.inputs.command == 'deploy' || github.event.inputs.command == 'build' }}
4348
runs-on: ubuntu-latest
4449
env:
4550
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -58,11 +63,12 @@ jobs:
5863
run: |
5964
docker push "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
6065
deploy:
61-
if: ${{ github.event.inputs.command == 'deploy' }}
66+
if: ${{ github.event.inputs.command == 'deploy' && github.event.inputs.env_name == 'dev' }}
6267
needs:
6368
- build
6469
- generate-env
65-
runs-on: self-hosted
70+
runs-on: [self-hosted,dev,docker]
71+
environment: dev
6672
env:
6773
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
6874
steps:
@@ -79,16 +85,37 @@ jobs:
7985
docker stop ceramicraft-user-mservice || true
8086
docker rm ceramicraft-user-mservice || true
8187
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 }}"
88+
swarm-deploy:
89+
if: ${{ github.event.inputs.command == 'deploy' && github.event.inputs.env_name == 'prod' }}
90+
runs-on: [self-hosted,prod,swarm]
91+
environment: prod
92+
needs: build
93+
env:
94+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
95+
steps:
96+
- name: pull the docker image
97+
run: |
98+
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
99+
- name: update the service
100+
run: |
101+
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
82102
restart:
83-
if: ${{ github.event.inputs.command == 'restart' }}
84-
runs-on: self-hosted
103+
if: ${{ github.event.inputs.command == 'restart' && github.event.inputs.env_name == 'dev' }}
104+
runs-on: [self-hosted,dev,docker]
85105
steps:
86106
- name: restart docker container
87107
run: |
88108
docker restart ceramicraft-user-mservice || true
109+
swarm_restart:
110+
if: ${{ github.event.inputs.command == 'restart' && github.event.inputs.env_name == 'prod' }}
111+
runs-on: [self-hosted,prod,swarm]
112+
steps:
113+
- name: restart the service
114+
run: |
115+
docker service update --force ms-stack_user-ms || true
89116
rollback:
90-
if: ${{ github.event.inputs.command == 'rollback' }}
91-
runs-on: self-hosted
117+
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'dev' }}
118+
runs-on: [self-hosted,dev,docker]
92119
needs: generate-env
93120
env:
94121
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -106,10 +133,9 @@ jobs:
106133
docker stop ceramicraft-user-mservice || true
107134
docker rm ceramicraft-user-mservice || true
108135
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
136+
swarm-rollback:
137+
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'prod' }}
138+
runs-on: [self-hosted,prod,swarm]
113139
env:
114140
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
115141
steps:
@@ -118,4 +144,4 @@ jobs:
118144
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
119145
- name: update the service
120146
run: |
121-
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
147+
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)