Skip to content

Commit

Permalink
Merge pull request #291 from BronzBierd/tasks/SCV-459
Browse files Browse the repository at this point in the history
SCV-459 - Add Dockerfiles for composite build pattern for GithubActions
  • Loading branch information
WadeBarnes authored Dec 18, 2024
2 parents 2d49916 + 797b0fd commit ae99cab
Show file tree
Hide file tree
Showing 20 changed files with 550 additions and 550 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"christian-kohler.path-intellisense",
"ms-dotnettools.csdevkit",
"ms-dotnettools.csharp",
"ms-dotnettools.vscode-dotnet-runtime",
"foxundermoon.shell-format"
"ms-dotnettools.vscode-dotnet-runtime"
],
"settings": {
"editor.codeActionsOnSave": {
Expand Down
45 changes: 45 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# Pull Request for JIRA Ticket: ----**put ticket number here**----

## Issue ticket number and link
Include the JIRA ticket # and link here

## Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

- [ ] Test A
- [ ] Test B

**Test Configuration**:
If applicable

## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules


## Documentation References

Put any doc references here
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build docker and push to artifactory repo
description: perform a build and tag and push to a desired repo. Artifactory secrets should be set.

inputs:
docker_context_directory:
type: string
description: The directory to work in
default: ./
image_name:
type: string
description: The name of the image to build
required: true
image_tag:
type: string
description: The docker image tag
required: true
artifactory_repo:
type: string
description: The Artifactory repository to push the image to
required: true
artifactory_image_path:
type: string
description: The path in the Artifactory repository to push the image to
required: true
build_dockerfile:
type: string
description: The path to the Dockerfile to build
docker_target:
type: string
description: The build stage target to build in the Dockerfile. Optional will build final stage by default.
docker_build_args:
type: string
description: The build arguments to pass to the Dockerfile. Pipe separated list of key=value pairs.
runs:
using: composite

steps:
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Artifactory
uses: docker/login-action@v3
with:
registry: ${{ inputs.artifactory_repo }}
username: ${{ secrets.ARTIFACTORY_USERNAME }}
password: ${{ secrets.ARTIFACTORY_PASSWORD }}

- name: Setup Image Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ inputs.artifactory_repo }}/${{ inputs.artifactory_image_path }}/${{ inputs.image_name }}
tags: |
type=raw,value=${{ inputs.artifactory_repo }}/${{ inputs.artifactory_image_path }}/${{ inputs.image_name }}:${{ inputs.image_tag }}
- name: Build and Push Image to artifactory.io
uses: docker/build-push-action@v5
with:
push: true
context: ${{ inputs.docker_context_directory }}
file: ${{ inputs.build_dockerfile || 'Dockerfile' }}
build-args: ${{ inputs.docker_build_args }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Docker build target refers to the build stage in the docker files
# requiring a value here will make the shareable action difficult to use.
# Ommitting the target will build the final stage by default.
# https://docs.docker.com/get-started/docker-concepts/building-images/multi-stage-builds/#:~:text=In%20your%20multi,stage%20by%20default.
target: ${{ inputs.docker_target }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
62 changes: 62 additions & 0 deletions .github/workflows/actions/update-argo-repo/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Update Argo CD gitops repo
description: Update the gitops tenant repository with the latest image tag

inputs:
licence_plate:
type: string
description: The OpenShift licence plate
required: true
gitops_branch:
type: string
description: The branch to update standard branches for tenant-gitops (develop, test, prod)
required: true
image_tag:
type: string
description: The image tag to update
required: true
helm_property:
type: string
description: The property in the Helm values file to update
required: true
helm_paths:
type: string
description: space separated list of paths to the Helm values files to update
required: true

runs:
using: composite

steps:
- name: Checkout ArgoCD Repo
id: gitops
uses: actions/checkout@v4
with:
repository: bcgov-c/tenant-gitops-${{ inputs.licence_plate }}
ref: ${{ inputs.gitops_branch }}
token: ${{ secrets.GIT_OPS_SSH_KEY }} # `GH_PAT` is a secret that contains your PAT
path: gitops

- name: Update Helm Values and Commit
id: helm
if: steps.gitops.outcome == 'success'
run: |
# Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and
cd gitops/charts
# Update the Helm values file with the new image tag and version
DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time
# Split incoming helm_paths by space into an array and loop through each path update the image tag in each file
IFS=' ' read -r -a paths <<< "${{ inputs.helm_paths }}"
for path in "${paths[@]}"; do
sed -i "s/${{ inputs.helm_property }}: .*/${{ inputs.helm_property }}: ${{ inputs.image_tag }} # Image Updated on $DATETIME/" $path
# Stage the changed path immediately for upcoming commit
git add $path
done
# Commit and push the changes
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git commit -m "Update API image tag"
git push origin ${{ inputs.gitops_branch }}
54 changes: 54 additions & 0 deletions .github/workflows/cd-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: API

on:
push:
branches: [master]
paths:
- "api/**"
- "docker/api/**"
- ".github/workflows/actions/**"
- ".github/workflows/cd-api.yaml"
workflow_dispatch:
env:
IMAGE_NAME: api
IMAGE_TAG_PREFIX: dev
WORKING_DIRECTORY: ./
GITOPS_BRANCH: develop
GITOPS_LICENCE_PLATE: b3c707
ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca
ARTIFACTORY_IMAGE_PATH: sbc3-images
BUILD_DOCKERFILE: api/Dockerfile.release
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Get short SHA
id: short_sha
run: |
echo "::set-output name=SHORT_SHA::$(git rev-parse --short HEAD)"
echo "Short SHA: $SHORT_SHA"
- name: Build and Push API images to Artifactory
id: build_push
uses: ./.github/workflows/actions/docker-build-push-artifactory
with:
image_name: ${{ env.IMAGE_NAME }}
image_tag: ${{ env.IMAGE_TAG_PREFIX }}-${{ steps.short_sha.outputs.SHORT_SHA }}
artifactory_repo: ${{ env.ARTIFACTORY_REPO }}
artifactory_image_path: ${{ env.ARTIFACTORY_IMAGE_PATH }}
build_dockerfile: ${{ env.BUILD_DOCKERFILE }}

- name: Update ArgoCD Repo
id: update_argo_repo
if: steps.build_push.outcome == 'success'
uses: ./.github/workflows/actions/update-argo-repo
with:
licence_plate: ${{ env.GITOPS_LICENCE_PLATE }}
gitops_branch: ${{ env.GITOPS_BRANCH }}
image_tag: ${{ env.IMAGE_TAG_PREFIX }}-${{ steps.short_sha.outputs.SHORT_SHA }}
helm_property: /apitag
helm_paths: "api/values.yaml ../develop/values.yaml"
30 changes: 30 additions & 0 deletions .github/workflows/cd-backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Backup

on:
workflow_dispatch:
env:
IMAGE_NAME: backup
WORKING_DIRECTORY: ./
ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca
ARTIFACTORY_IMAGE_PATH: sbc3-images
BUILD_DOCKERFILE: api/Dockerfile.release
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Backup Container Repo
id: gitops
uses: actions/checkout@v4
with:
repository: BCDevOps/backup-container.git
ref: 2.9.0

- name: Docker Build Backup Image and push to Artifactory
uses: ./.github/workflows/actions/docker-build-push-artifactory
with:
docker_context_directory: docker
image_name: ${{ env.IMAGE_NAME }}
image_tag: latest
artifactory_repo: ${{ env.ARTIFACTORY_REPO }}
artifactory_image_path: ${{ env.ARTIFACTORY_IMAGE_PATH }}
29 changes: 29 additions & 0 deletions .github/workflows/cd-schema-spy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Schema-Spy

on:
workflow_dispatch:
env:
IMAGE_NAME: schema-spy
WORKING_DIRECTORY: ./
ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca
ARTIFACTORY_IMAGE_PATH: sbc3-images
BUILD_DOCKERFILE: api/Dockerfile.release
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Schema Spy Repo
id: gitops
uses: actions/checkout@v4
with:
repository: bcgov/SchemaSpy.git
ref: master

- name: Docker Build Schema Spy Image and push to Artifactory
uses: ./.github/workflows/actions/docker-build-push-artifactory
with:
image_name: ${{ env.IMAGE_NAME }}
image_tag: latest
artifactory_repo: ${{ env.ARTIFACTORY_REPO }}
artifactory_image_path: ${{ env.ARTIFACTORY_IMAGE_PATH }}
58 changes: 58 additions & 0 deletions .github/workflows/cd-web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Web

on:
push:
branches: [master]
paths:
- "web/**"
- "docker/web/**"
- ".github/workflows/actions/**"
- ".github/workflows/cd-web.yaml"
workflow_dispatch:
env:
IMAGE_NAME: web
IMAGE_TAG_PREFIX: dev
WORKING_DIRECTORY: ./
GITOPS_BRANCH: develop
GITOPS_LICENCE_PLATE: b3c707
ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca
ARTIFACTORY_IMAGE_PATH: sbc3-images

jobs:
builds:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Get short SHA
id: short_sha
run: |
echo "::set-output name=SHORT_SHA::$(git rev-parse --short HEAD)"
echo "Short SHA: $SHORT_SHA"
- name: Build and Push API images to Artifactory
id: build_push
uses: ./.github/workflows/actions/docker-build-push-artifactory
with:
image_name: ${{ env.IMAGE_NAME }}
image_tag: ${{ env.IMAGE_TAG_PREFIX }}-${{ steps.short_sha.outputs.SHORT_SHA }}
artifactory_repo: ${{ env.ARTIFACTORY_REPO }}
artifactory_image_path: ${{ env.ARTIFACTORY_IMAGE_PATH }}
build_dockerfile: web/Dockerfile.release
build_docker_args: |
NGINX_RUNTIME_SRC='./docker/nginx-runtime'
VUE_ON_NGINX_SRC='./docker/vue-on-nginx'
WEB_SRC='./docker/web'
- name: Update ArgoCD Repo
id: update_argo_repo
if: steps.build_push.outcome == 'success'
uses: ./.github/workflows/actions/update-argo-repo
with:
licence_plate: ${{ env.GITOPS_LICENCE_PLATE }}
gitops_branch: ${{ env.GITOPS_BRANCH }}
image_tag: ${{ env.IMAGE_TAG_PREFIX }}-${{ steps.short_sha.outputs.SHORT_SHA }}
helm_property: /webtag
helm_paths: web/values.yaml ../develop/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: API (.NET Core)
name: CI - API (.NET Core)

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: APP (Vue)
name: CI - APP (Vue)

on:
push:
Expand Down
9 changes: 9 additions & 0 deletions docker/api/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0

ENV ASPNETCORE_ENVIRONMENT='Production'
ENV ASPNETCORE_URLS='http://+:5000'
ENV CORS_DOMAIN='http://localhost:8080'
ENV DOTNET_STARTUP_PROJECT='./api/api.csproj'
ENV DOTNET_USE_POLLING_FILE_WATCHER=1

RUN curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l /vsdbg
Loading

0 comments on commit ae99cab

Please sign in to comment.