Skip to content

Commit 2ab72dc

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

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 50 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,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.environment == '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,20 +87,50 @@ 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.environment == '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.environment }}
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.environment == '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 }}
95129
steps:
130+
- name: Debug Inputs
131+
run: |
132+
echo "Command: ${{ github.event.inputs.command }}"
133+
echo "Environment: ${{ github.event.inputs.environment }}"
96134
- name: Download .env file
97135
uses: actions/download-artifact@v4
98136
with:
@@ -106,10 +144,10 @@ jobs:
106144
docker stop ceramicraft-user-mservice || true
107145
docker rm ceramicraft-user-mservice || true
108146
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
147+
swarm-rollback:
148+
if: ${{ github.event.inputs.command == 'rollback' }} && ${{ github.event.inputs.environment == 'prod' }}
149+
runs-on: [self-hosted,prod,swarm]
150+
environment: prod
113151
env:
114152
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
115153
steps:
@@ -118,4 +156,4 @@ jobs:
118156
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
119157
- name: update the service
120158
run: |
121-
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
159+
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)