Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ name: Deploy Go to EC2 (manual)
on:
workflow_dispatch: # ← Manual trigger button
inputs:
env_name:
description: 'env_name'
required: true
default: 'dev'
type: choice
options:
- prod
- dev
version:
description: 'version'
required: false
Expand All @@ -16,16 +24,13 @@ on:
options:
- build
- deploy
- swarm-deploy
- restart
- rollback

jobs:
generate-env:
name: Generate .env file
runs-on: ubuntu-latest
outputs:
env-path: ${{ steps.set-output.outputs.env-path }}
steps:
- name: Generate .env file
run: |
Expand All @@ -39,7 +44,7 @@ jobs:
name: env-file
path: env-file
build:
if: ${{ github.event.inputs.command == 'deploy' }} || ${{ github.event.inputs.command == 'build' }} || ${{ github.event.inputs.command == 'swarm-deploy' }}
if: ${{ github.event.inputs.command == 'deploy' || github.event.inputs.command == 'build' }}
runs-on: ubuntu-latest
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
Expand All @@ -58,11 +63,12 @@ jobs:
run: |
docker push "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
deploy:
if: ${{ github.event.inputs.command == 'deploy' }}
if: ${{ github.event.inputs.command == 'deploy' && github.event.inputs.env_name == 'dev' }}
needs:
- build
- generate-env
runs-on: self-hosted
runs-on: [self-hosted,dev,docker]
environment: dev
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
steps:
Expand All @@ -79,16 +85,37 @@ jobs:
docker stop ceramicraft-user-mservice || true
docker rm ceramicraft-user-mservice || true
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 }}"
swarm-deploy:
if: ${{ github.event.inputs.command == 'deploy' && github.event.inputs.env_name == 'prod' }}
runs-on: [self-hosted,prod,swarm]
environment: prod
needs: build
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
steps:
- name: pull the docker image
run: |
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
- name: update the service
run: |
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
restart:
if: ${{ github.event.inputs.command == 'restart' }}
runs-on: self-hosted
if: ${{ github.event.inputs.command == 'restart' && github.event.inputs.env_name == 'dev' }}
runs-on: [self-hosted,dev,docker]
steps:
- name: restart docker container
run: |
docker restart ceramicraft-user-mservice || true
swarm_restart:
if: ${{ github.event.inputs.command == 'restart' && github.event.inputs.env_name == 'prod' }}
runs-on: [self-hosted,prod,swarm]
steps:
- name: restart the service
run: |
docker service update --force ms-stack_user-ms || true
rollback:
if: ${{ github.event.inputs.command == 'rollback' }}
runs-on: self-hosted
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'dev' }}
runs-on: [self-hosted,dev,docker]
needs: generate-env
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
Expand All @@ -106,10 +133,9 @@ jobs:
docker stop ceramicraft-user-mservice || true
docker rm ceramicraft-user-mservice || true
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 }}"
swarm-deploy:
if: ${{ github.event.inputs.command == 'swam-deploy' }}
runs-on: self-hosted
needs: build
swarm-rollback:
if: ${{ github.event.inputs.command == 'rollback' && github.event.inputs.env_name == 'prod' }}
runs-on: [self-hosted,prod,swarm]
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
steps:
Expand All @@ -118,4 +144,4 @@ jobs:
docker pull "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
- name: update the service
run: |
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
docker service update --force --image "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}" ms-stack_user-ms || true
Loading