Skip to content

Commit

Permalink
chore(ci): add var to deployments (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Mar 29, 2024
1 parent c03dbe7 commit 9c9195e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 32 deletions.
40 changes: 12 additions & 28 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ on:
workflow_call:
inputs:
### Required
tag:
description: GitHub package tag; e.g. PR number or PROD
required: false
type: string

target:
description: PR number, test or prod
description: Deployment target; e.g. PR number, test or prod
required: true
type: string

Expand All @@ -15,8 +20,8 @@ on:
required: false
type: string

tag:
description: GitHub package tag; omit for PRs
parameters:
description: Template parameters/variables to pass (e.g. -p ZONE=...)
required: false
type: string

Expand All @@ -36,31 +41,8 @@ env:
JOB_JOB: ${{ github.event.repository.name }}-${{ inputs.target }}-sync-${{ github.run_number }}

jobs:
vars:
name: Set Variables
outputs:
tag: ${{ steps.vars.outputs.tag }}
runs-on: ubuntu-latest
steps:
# Get PR number for squash merges to main
- name: PR Number
id: pr
uses: bcgov-nr/action-get-pr@v0.0.1

- name: Set Variables
id: vars
run: |
if [ -z "${{ inputs.tag }}" ]; then
echo "No tag provided, using most recent PR merge number."
echo "tag=${{ steps.pr.outputs.pr }}" >> $GITHUB_ENV
else
echo "Tag provided and being used for deployment."
echo "tag=${{ inputs.tag }}" >> $GITHUB_ENV
fi
deploy:
name: Deploy and Run Job
needs: [vars]
name: Deploy
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
steps:
Expand All @@ -73,7 +55,9 @@ jobs:
oc_token: ${{ secrets.OC_TOKEN }}
oc_version: 4.13
overwrite: true
parameters: -p ZONE=${{ inputs.target }} -p TAG=${{ needs.vars.outputs.tag }}
parameters:
-p ZONE=${{ inputs.target }} -p TAG=${{ inputs.tag }}
${{ inputs.parameters}}
post_rollout: oc create job ${{ env.JOB_JOB }} --from=cronjob/${{ env.CRONJOB }}
triggers: ${{ inputs.triggers }}

Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ concurrency:
cancel-in-progress: false

jobs:
vars:
name: Set Variables
outputs:
pr: ${{ steps.pr.outputs.pr }}
runs-on: ubuntu-22.04
timeout-minutes: 1
steps:
# Get PR number for squash merges to main
- name: PR Number
id: pr
uses: bcgov-nr/action-get-pr@v0.0.1

deploy:
name: Deploy and Run Job
needs: [vars]
secrets: inherit
uses: ./.github/workflows/.deploy.yml
with:
environment: test
tag: ${{ needs.vars.outputs.pr }}
target: test
verify: false

Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ jobs:
build:
name: Build
runs-on: ubuntu-22.04
outputs:
digest: ${{ steps.build.outputs.digest }}
permissions:
packages: write
timeout-minutes: 10
steps:
- uses: bcgov-nr/action-builder-ghcr@v2.0.2
id: build
with:
keep_versions: 50
package: sync
Expand All @@ -26,12 +29,14 @@ jobs:
triggers: ('sync/')

deploy:
name: Deploy and Run Job
name: Deploy
if: needs.build.outputs.digest != ''
needs: [build]
secrets: inherit
uses: ./.github/workflows/.deploy.yml
with:
parameters: -p TEST_MODE=1
tag: ${{ github.event.number }}
target: ${{ github.event.number }}

results:
Expand Down
7 changes: 5 additions & 2 deletions sync/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ RUN apt update && \
apt install -y --no-install-recommends gcc libpq-dev python3-dev

# Disable cache dir, disable upgrade message, create .venv in project dir
ARG PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on
ARG PIP_NO_CACHE_DIR="off" \
PIP_DISABLE_PIP_VERSION_CHECK="on" \
PIP_DEFAULT_TIMEOUT="100" \
PYTHONDONTWRITEBYTECODE="1" \
PYTHONUNBUFFERED="1"

# Copy files and install requirements
WORKDIR /app
Expand Down
7 changes: 6 additions & 1 deletion sync/openshift.etl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ parameters:
- name: REPO
description: Repository name
value: nr-spar-data
- name: TEST_MODE
description: "Run in test mode"
value: "1"

### Usually a bad idea - not recommended
- name: CRON_MINUTES
Expand Down Expand Up @@ -67,7 +70,9 @@ objects:
containers:
- name: ${REPO}-${ZONE}
image: "${REGISTRY}/${ORG}/${REPO}/${APP}:${TAG}"
# env:
env:
- name: test_mode
value: "${TEST_MODE}"
# - name: POSTGRES_SERVICE
# value: "${REPO}-${ZONE}-database"
resources:
Expand Down

0 comments on commit 9c9195e

Please sign in to comment.