Skip to content

Commit a854d4e

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

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 46 additions & 12 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,42 @@ 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:
83105
if: ${{ github.event.inputs.command == 'restart' }}
84-
runs-on: self-hosted
106+
environment: ${{ github.event.inputs.env_name }}
107+
runs-on: ${{ matrix.runner}}
108+
strategy:
109+
matrix:
110+
environment: [dev, prod]
111+
include:
112+
- environment: dev
113+
runner: [self-hosted, dev, docker]
114+
- environment: prod
115+
runner: [self-hosted, prod, swarm]
116+
runner: [self-hosted, dev, docker, prod, swarm]
85117
steps:
86118
- name: restart docker container
87119
run: |
120+
echo "Restarting container on ${{ matrix.environment }} environment"
88121
docker restart ceramicraft-user-mservice || true
89122
rollback:
90-
if: ${{ github.event.inputs.command == 'rollback' }}
91-
runs-on: self-hosted
123+
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'dev' }}
124+
runs-on: [self-hosted, dev, docker]
125+
environment: dev
92126
needs: generate-env
93127
env:
94128
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -106,10 +140,10 @@ jobs:
106140
docker stop ceramicraft-user-mservice || true
107141
docker rm ceramicraft-user-mservice || true
108142
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
143+
swarm-rollback:
144+
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'prod' }}
145+
runs-on: [self-hosted,prod,swarm]
146+
environment: prod
113147
env:
114148
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
115149
steps:
@@ -118,4 +152,4 @@ jobs:
118152
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
119153
- name: update the service
120154
run: |
121-
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
155+
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)