Skip to content

db-migrate-workflow #57

db-migrate-workflow

db-migrate-workflow #57

name: db-migrate-workflow
on:
workflow_dispatch:
inputs:
environment:
required: true
type: choice
options:
- dev
- test
- prod
checkout_branch:
required: true
type: choice
options:
- main
- release/1.0
push:
branches:
- patch/dbmigrate
jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
environment: ${{ inputs.environment }}
env:
checkout_branch: ${{ inputs.checkout_branch }}
DOCKER_IMAGE_NAME: db-migrate-image
DOCKER_CONTEXT_FOLDER: python
DOCKER_FILE: python/prohibition_web_svc/Dockerfile-migration
DOCKER_IMAGE_TAG: latest
namespace: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout_branch }}
# ref: ${{ env.checkout_branch }}
- name: Setup
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Login
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Tag
id: tag
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_prefix: ${{ env.DOCKER_IMAGE_NAME }}=v
fetch_all_tags: true
- name: Build
uses: docker/build-push-action@v3
with:
context: ${{ env.DOCKER_CONTEXT_FOLDER }}
file: ${{ env.DOCKER_FILE }}
push: true
tags: ${{ secrets.DOCKER_REGISTRY }}/dbe7-images/${{ env.DOCKER_IMAGE_NAME }}-${{ inputs.environment }}:${{ env.DOCKER_IMAGE_TAG }}
- name: Authenticate and set context
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL_SILVER }}
openshift_token: ${{ secrets.OPENSHIFT_SA_PIPELINE_TOKEN_SILVER_ENV }}
namespace: "${{ secrets.OPENSHIFT_LICENSE_PLATE_SILVER }}-${{ inputs.environment }}"
- name: Run Migration
run: |
oc delete job db-migrate-job --ignore-not-found=true
oc process -f migrate-job.yml --param IMAGE_NAME=${{ secrets.DOCKER_REGISTRY }}/dbe7-images/${{ env.DOCKER_IMAGE_NAME }}-${{ inputs.environment }}:${{ env.DOCKER_IMAGE_TAG }} --param DB_HOST=${{ secrets.DB_HOST }} --param DB_NAME=${{ secrets.DB_NAME }} --param DB_PORT=${{ secrets.DB_PORT }} --param DB_USER=${{ secrets.DB_USER }} --param DB_PASS=${{ secrets.DB_PASS }} | oc apply -f -