Skip to content

(Production) Release & Deploy Docker Image #4

(Production) Release & Deploy Docker Image

(Production) Release & Deploy Docker Image #4

name: (Production) Release & Deploy Docker Image
on:
push:
tags:
- "v*"
workflow_dispatch:
jobs:
Variables:
runs-on: ubuntu-latest
outputs:
image_tag: ${{steps.vars.outputs.image_tag}}
microservice: syllibot
context_dir: "."
deployment_servers: '["syllibot"]'
microservice_env: prod
image_registry: ghcr.io/${{ github.repository_owner }}
steps:
- name: Create Timestamp Variable for image tag
id: vars
#Edit variables down here for values
run: |
echo "image_tag=$(date +'%Y-%m-%d--%H-%M-%S')" >> "$GITHUB_OUTPUT"
Debug:
needs: Variables
runs-on: ubuntu-latest
steps:
- name: Debug information
run: |
echo "=== Variables ==="
echo "Time Var: ${{ needs.variables.outputs.image_tag }}"
echo "Variable: ${{ needs.variables.outputs.microservice }}"
echo "Variable: ${{ needs.variables.outputs.microservice_path }}"
echo "Variable: ${{ needs.variables.outputs.microservice_port }}"
echo "Variable: ${{ needs.variables.outputs.microservice_env }}"
echo "Variable: ${{ needs.variables.outputs.context_dir }}"
echo "Variable: ${{ needs.variables.outputs.image_registry }}"
Create-Docker-Image:
needs: [Debug, Variables]
uses: ./.github/workflows/build-push-docker-image.yml
with:
image_tag: ${{ needs.variables.outputs.image_tag }}
microservice: ${{needs.variables.outputs.microservice}}
microservice_path: ${{needs.variables.outputs.microservice_path}}
context_dir: ${{needs.variables.outputs.microservice_path}}
microservice_env: ${{needs.variables.outputs.microservice_env}}
image_registry: ${{needs.variables.outputs.image_registry}}
# Deploy-Docker-Image:
# needs: [Variables, Create-Docker-Image]
# uses: ./.github/workflows/deploy-docker-image.yml
# with:
# image_tag: ${{needs.variables.outputs.image_tag}}
# microservice: ${{needs.variables.outputs.microservice}}
# microservice_env: ${{needs.variables.outputs.microservice_env}}
# deployment_servers: ${{needs.variables.outputs.deployment_servers}}
# # secrets:
# # ssh_key: ${{secrets.SSH_PRIVATE_KEY}}
Deploy-Microservice:
needs: [Create-Docker-Image, Debug, Variables]
runs-on: [self-hosted, "${{ matrix.deployment_server }}" ]
strategy:
matrix:
deployment_server: ${{ fromJson(needs.variables.outputs.deployment_servers) }}
steps:
- uses: actions/checkout@v3
- name: Docker stop old container
run: |
docker container rm -f ${{needs.variables.outputs.microservice}}-${{needs.variables.outputs.microservice_env}} || $true
- name: Docker start new container
run: >-
docker run
--name ${{needs.variables.outputs.microservice}}-${{needs.variables.outputs.microservice_env}}
--restart always
-e APP_VERSION=$GITHUB_REF_NAME
-e DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}
-e environment=${{needs.variables.outputs.microservice_env}}
--add-host host.docker.internal:host-gateway
-d ghcr.io/agent-artificial/${{needs.variables.outputs.microservice}}-${{needs.variables.outputs.microservice_env}}:${{needs.variables.outputs.image_tag}}