Skip to content

Commit 2dbecfc

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

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 41 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+
environment:
7+
description: 'environment'
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,11 @@ 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.environment == 'dev' }}
6269
needs:
6370
- build
6471
- generate-env
65-
runs-on: self-hosted
72+
runs-on: [self-hosted, dev, docker]
6673
env:
6774
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
6875
steps:
@@ -79,16 +86,39 @@ jobs:
7986
docker stop ceramicraft-user-mservice || true
8087
docker rm ceramicraft-user-mservice || true
8188
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 }}"
89+
swarm-deploy:
90+
if: ${{ github.event.inputs.command == 'deploy' }} && ${{ github.event.inputs.environment == 'prod' }}
91+
runs-on: [self-hosted,prod,swarm]
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:
83103
if: ${{ github.event.inputs.command == 'restart' }}
84-
runs-on: self-hosted
104+
runs-on: ${{ matrix.runner}}
105+
strategy:
106+
matrix:
107+
environment: [dev, prod]
108+
include:
109+
- environment: dev
110+
runner: [self-hosted, dev, docker]
111+
- environment: prod
112+
runner: [self-hosted, prod, swarm]
113+
runner: [self-hosted, dev, docker, prod, swarm]
85114
steps:
86115
- name: restart docker container
87116
run: |
117+
echo "Restarting container on ${{ matrix.environment }} environment"
88118
docker restart ceramicraft-user-mservice || true
89119
rollback:
90-
if: ${{ github.event.inputs.command == 'rollback' }}
91-
runs-on: self-hosted
120+
if: ${{ github.event.inputs.command == 'rollback' }} && ${{ github.event.inputs.environment == 'dev' }}
121+
runs-on: [self-hosted, dev, docker]
92122
needs: generate-env
93123
env:
94124
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -106,10 +136,9 @@ jobs:
106136
docker stop ceramicraft-user-mservice || true
107137
docker rm ceramicraft-user-mservice || true
108138
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
139+
swarm-rollback:
140+
if: ${{ github.event.inputs.command == 'rollback' }} && ${{ github.event.inputs.environment == 'prod' }}
141+
runs-on: [self-hosted,prod,swarm]
113142
env:
114143
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
115144
steps:
@@ -118,4 +147,4 @@ jobs:
118147
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
119148
- name: update the service
120149
run: |
121-
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
150+
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)