Deploy Services to Gold and Gold DR #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Services to Gold and Gold DR | |
on: | |
workflow_dispatch: | |
inputs: | |
service: | |
description: 'Select services to deploy' | |
required: true | |
default: 'all' | |
type: choice | |
options: | |
- all | |
- ClaimService | |
- ConsentService | |
- LocationService | |
- MedicationService | |
- MedicationDispenseService | |
- MedicationRequestService | |
- MedicationStatementService | |
- PatientService | |
- PractitionerService | |
environment: | |
description: 'Deploy to' | |
required: true | |
default: 'vc1' | |
type: choice | |
options: | |
- vc1 | |
jobs: | |
prepare-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- id: set-matrix | |
# Creates the matrix values from the input, replacing the string "all" with a list of all services | |
run: echo "matrix={\"service\":[\"${{ inputs.service }}\"]}" | sed -r 's/\"all\"/\"ClaimService\", \"ConsentService\", \"LocationService\", \"MedicationService\", \"MedicationDispenseService\", \"MedicationRequestService\", \"MedicationStatementService\", \"PatientService\", \"PractitionerService\"/' >> $GITHUB_OUTPUT | |
build: | |
runs-on: ubuntu-latest | |
needs: prepare-matrix | |
strategy: | |
matrix: ${{ fromJSON(needs.prepare-matrix.outputs.matrix) }} | |
steps: | |
- name: "Checkout source" | |
uses: actions/checkout@v3 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v2.1.0 | |
- name: Building ${{ matrix.service }} | |
run: | | |
buildid=$(date +"%Y%m%d").$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER.$GITHUB_RUN_ATTEMPT | |
echo Starting C# Build as $buildid | |
dotnet publish $GITHUB_WORKSPACE/Services/${{ matrix.service }}/src/${{ matrix.service }}.csproj -o $RUNNER_TEMP -c Release | |
echo Starting Docker Build | |
imageName=${{ secrets.GOLD_IMAGE_REPOSITORY }}/${{ secrets.GOLD_TOOLS_NAMESPACE }}/$(echo ${{ matrix.service }} | tr '[:upper:]' '[:lower:]') | |
docker build -f $GITHUB_WORKSPACE/Services/${{ matrix.service }}/src/Dockerfile $RUNNER_TEMP -t $imageName:${{ inputs.environment }} | |
- name: OpenShift Gold Login | |
uses: redhat-actions/oc-login@v1.1 | |
with: | |
openshift_server_url: ${{ secrets.GOLD_URI }} | |
openshift_token: ${{ secrets.GOLD_TOKEN }} | |
namespace: ${{ secrets.GOLD_TOOLS_NAMSPACE }} | |
- name: Pushing ${{ matrix.service }} to Gold | |
run: | | |
imageName=${{ secrets.GOLD_IMAGE_REPOSITORY }}/${{ secrets.GOLD_TOOLS_NAMESPACE }}/$(echo ${{ matrix.service }} | tr '[:upper:]' '[:lower:]') | |
docker login -u ${{ secrets.OPENSHIFT_USER }} -p `oc whoami --show-token` ${{ secrets.GOLD_IMAGE_REPOSITORY }} | |
docker push $imageName:${{ inputs.environment }} | |
- name: OpenShift Gold DR Login | |
uses: redhat-actions/oc-login@v1.1 | |
with: | |
openshift_server_url: ${{ secrets.GOLDDR_URI }} | |
openshift_token: ${{ secrets.GOLDDR_TOKEN }} | |
namespace: ${{ secrets.GOLDDR_TOOLS_NAMSPACE }} | |
- name: Tag and Push ${{ matrix.service }} to Gold DR | |
run: | | |
srcImageName=${{ secrets.GOLD_IMAGE_REPOSITORY }}/${{ secrets.GOLD_TOOLS_NAMESPACE }}/$(echo ${{ matrix.service }} | tr '[:upper:]' '[:lower:]') | |
dstImageName=${{ secrets.GOLDDR_IMAGE_REPOSITORY }}/${{ secrets.GOLDDR_TOOLS_NAMESPACE }}/$(echo ${{ matrix.service }} | tr '[:upper:]' '[:lower:]') | |
docker tag $srcImageName:${{ inputs.environment }} $dstImageName:${{ inputs.environment }} | |
docker login -u ${{ secrets.OPENSHIFT_USER }} -p `oc whoami --show-token` ${{ secrets.GOLDDR_IMAGE_REPOSITORY }} | |
docker push $dstImageName:${{ inputs.environment }} |