Skip to content

Manual rollback to specific image #2

Manual rollback to specific image

Manual rollback to specific image #2

Workflow file for this run

name: Manual rollback to specific image
on:
workflow_dispatch:
inputs:
client_backend:
description: 'Choice frontend or backend'
required: true
default: 'frontend'
type: choice
options:
- frontend
- backend
tag_version:
description: 'Enter the service version to deploy'
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Display variables
run: |
echo "Environment to rollback: ${{ github.event.inputs.client_backend }}"
echo "Tag to rollback: ${{ github.event.inputs.tag_version }}"
###############################################################################
# DEPLOY client
###############################################################################
deploy_frontend:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.client_backend == 'frontend' }}
env:
DEPLOYMENT_SERVER_HOST: ${{ vars.SERVER_HOST }}
APP_ENDPOINT: http://${{ vars.SERVER_HOST }}
SERVICE: frontend
APP_PORT: 80
HOST_PORT: 8000
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Extract Info
id: extract_info
run: |
repository=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "REPOSITORY=$repository" >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build development environment in frontend server
uses: appleboy/[email protected]
with:
host: ${{ vars.SERVER_HOST }}
username: admin
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
export IMAGE_NAME=ghcr.io/${{ env.REPOSITORY }}/${{ env.SERVICE }}
export TAG=${{ github.event.inputs.tag_version }}
mkdir -p ~/${{ env.SERVICE }}
cd ${{ env.SERVICE }}
echo COMPOSE_PROJECT_NAME=${{ env.SERVICE }} > .env
echo DC_IMAGE_NAME=$IMAGE_NAME >> .env
echo DC_IMAGE_TAG=$TAG >> .env
echo DC_APP_PORT=${{ env.APP_PORT }} >> .env
echo DC_HOST_PORT=${{ env.HOST_PORT }} >> .env
cat ./.env
- name: copy file via scp
uses: appleboy/[email protected]
with:
host: ${{ vars.SERVER_HOST }}
username: admin
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "./docker-compose.yaml"
target: "${{ env.SERVICE }}/"
- name: Run Dev container
uses: appleboy/[email protected]
with:
host: ${{ vars.SERVER_HOST }}
username: admin
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ env.SERVICE }}
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin
docker-compose down
docker-compose up -d
###############################################################################
# DEPLOY backend
###############################################################################
deploy_backend:
if: ${{ github.event.inputs.client_backend == 'backend' }}
runs-on: ubuntu-latest
env:
DEPLOYMENT_SERVER_HOST: ${{ vars.SERVER_HOST }}
APP_ENDPOINT: http://${{ vars.SERVER_HOST }}
SERVICE: backend
APP_PORT: 5000
HOST_PORT: 5000
GITHUB_TOKEN: ${{ github.token }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Extract info
id: extract_info
run: |
repository=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "REPOSITORY=$repository" >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build development environment in backend server
uses: appleboy/[email protected]
with:
host: ${{ vars.SERVER_HOST }}
username: admin
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
export IMAGE_NAME=ghcr.io/${{ env.REPOSITORY }}/${{ env.SERVICE }}
export TAG=${{ github.event.inputs.tag_version }}
mkdir -p ~/${{ env.SERVICE }}
cd ${{ env.SERVICE }}
echo COMPOSE_PROJECT_NAME=${{ env.SERVICE }} > .env
echo DC_IMAGE_NAME=$IMAGE_NAME >> .env
echo DC_IMAGE_TAG=$TAG >> .env
echo DC_APP_PORT=${{ env.APP_PORT }} >> .env
echo DC_HOST_PORT=${{ env.HOST_PORT }} >> .env
echo OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} >> .env
cat ./.env
- name: copy file via scp
uses: appleboy/[email protected]
with:
host: ${{ vars.SERVER_HOST }}
username: admin
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "./docker-compose.yaml"
target: "${{ env.SERVICE }}/"
- name: Run Dev container
uses: appleboy/[email protected]
with:
host: ${{ vars.SERVER_HOST }}
username: admin
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ env.SERVICE }}
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin
docker-compose down
docker-compose up -d