-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* app-build wf * refactor again * helm refactor * simplify image tagging * tidy env vars * trip env vars * tidy
- Loading branch information
Showing
4 changed files
with
209 additions
and
162 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: build-app | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
fullSemVer: | ||
type: string | ||
description: e.g. 1.2.3-feature-my-feature.12 | ||
required: true | ||
|
||
jobs: | ||
build-app: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: dotnet restore | ||
run: dotnet restore --verbosity minimal --configfile NuGet.config | ||
|
||
- name: dotnet build | ||
run: dotnet build -c Release --nologo --no-restore -p:Version='${{ inputs.fullSemVer }}' -p:SourceRevisionId=${{ github.sha }} | ||
|
||
#TODO: could run dotnet test here, etc... |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: build-chart | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
semVer: | ||
type: string | ||
description: e.g. 1.2.3-feature-my-feature.12 | ||
required: true | ||
|
||
jobs: | ||
build-chart: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write #for pushing helm package | ||
contents: write #for creating releases/tags | ||
env: | ||
REGISTRY: ghcr.io | ||
#CHART_REPOSITORY: Note: set dynamically, i.e. github.repository_owner/charts/IMAGE_NAME | ||
GIT_TAG: ${{ inputs.semVer }} | ||
HELM_EXPERIMENTAL_OCI: 1 | ||
HELM_VERSION_TO_INSTALL: 3.9.2 #Note: keep this version in sync inside the devcontainer | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 #Note: shallow clone may break git tag & ct lint... | ||
|
||
- name: set vars (1 of 3) | ||
run: | | ||
IMAGE_NAME=$(echo $REPOSITORY | sed "s|$USERNAME\/||g") | ||
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV | ||
- name: set vars (2 of 3) | ||
run: echo "CHART_REPOSITORY=${{ github.repository_owner }}/charts/$IMAGE_NAME" >> $GITHUB_ENV | ||
|
||
- name: set vars (3 of 3) #pulls helm version from devcontainer | ||
run: | | ||
HELM_VERSION_TO_INSTALL=$(cat .devcontainer/devcontainer.json | jq -r '.features."kubectl-helm-minikube".helm') | ||
echo "HELM_VERSION_TO_INSTALL=$HELM_VERSION_TO_INSTALL" >> $GITHUB_ENV | ||
- name: install helm | ||
uses: azure/setup-helm@v3 | ||
with: | ||
version: ${{ env.HELM_VERSION_TO_INSTALL }} | ||
|
||
- name: helm registry login | ||
run: | | ||
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${REGISTRY}/${CHART_REPOSITORY} --username ${{ github.repository_owner }} --password-stdin | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.7 | ||
if: false #not implemented/working yet | ||
|
||
- name: chart-testing (setup) | ||
uses: helm/chart-testing-action@v2 | ||
if: false #not implemented/working yet | ||
|
||
- name: chart-testing (run list-changed) | ||
id: list-changed | ||
run: | | ||
changed=$(ct list-changed --target-branch main) | ||
if [[ -n "$changed" ]]; then | ||
echo "::set-output name=changed::true" | ||
fi | ||
if: false #not implemented/working yet | ||
|
||
- name: chart-testing (run lint) | ||
run: ct lint | ||
if: false #not implemented/working yet | ||
|
||
- name: create kind cluster | ||
uses: helm/kind-action@v1 | ||
#if: steps.list-changed.outputs.changed == 'true' | ||
if: false #not implemented/working yet | ||
|
||
- name: chart-testing (run install) | ||
run: ct install | ||
if: false #not implemented/working yet | ||
|
||
- name: helm package | ||
run: | | ||
helm package ${{ github.workspace }}/charts/$IMAGE_NAME/ --destination ${{ github.workspace }}/artifacts/ --app-version ${{ env.GIT_TAG }} | ||
if: false #not implemented/working yet | ||
|
||
- name: helm push | ||
run: | | ||
helm push ${{ github.workspace }}/artifacts/$IMAGE_NAME-0.1.0.tgz oci://ghcr.io/${{ github.repository_owner }} | ||
if: false #not implemented/working yet, need to change the chart version in filename |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: build-image | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
semVer: | ||
type: string | ||
description: e.g. 1.2.3-feature-my-feature.12 | ||
required: true | ||
registry: | ||
type: string | ||
description: e.g. ghcr.io or docker.io | ||
default: ghcr.io | ||
tagOverride: | ||
type: string | ||
description: Default branch tag override, i.e. tag 1.2.3 -> latest | ||
default: latest | ||
devTagOverride: | ||
type: string | ||
description: Feature branch tag override, i.e. tag 1.2.3-feature-my-feature.12 -> latest-dev | ||
default: latest-dev | ||
platform: | ||
type: string | ||
description: Specify the target platform for the build output, e.g. linux/amd64,linux/arm64,linux/arm/v7 | ||
default: linux/amd64,linux/arm64,linux/arm/v7 | ||
|
||
jobs: | ||
build-image: | ||
runs-on: ubuntu-latest | ||
#https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ | ||
#https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs | ||
permissions: | ||
packages: write #for pushing container image | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: set vars (1 of 3) | ||
run: | | ||
IMAGE_NAME=$(echo ${{ github.repository }} | sed "s|${{ github.repository_owner }}\/||g") | ||
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV | ||
- name: set vars (2 of 3) | ||
if: github.ref != 'refs/heads/main' #feature branch use devTagOverride | ||
run: | | ||
echo "TAG=${{ inputs.devTagOverride }}" >> $GITHUB_ENV | ||
- name: set vars (3 of 3) | ||
if: github.ref == 'refs/heads/main' #default branch use tagOverride | ||
run: | | ||
echo "TAG=${{ inputs.tagOverride }}" >> $GITHUB_ENV | ||
echo "OVERRIDE_TAG=${{ inputs.semVer }}" >> $GITHUB_ENV | ||
- name: docker login ${{ inputs.registry }} | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ inputs.registry }} -u ${{ github.actor }} --password-stdin | ||
|
||
- name: docker buildx build/push | ||
run: | | ||
docker buildx create --name multiarchtest --use | ||
SOME_OPT=() | ||
if [ ! -z "$OVERRIDE_TAG" ]; then | ||
SOME_OPT=(-t "${{ inputs.registry }}/${{ github.repository }}:$OVERRIDE_TAG") | ||
fi | ||
docker buildx build \ | ||
-t ${{ inputs.registry }}/${{ github.repository }}:$TAG \ | ||
"${SOME_OPT[@]}" \ | ||
--label "GITHUB_RUN_ID=${{ github.run_id }}" \ | ||
--label "IMAGE_NAME=$IMAGE_NAME" \ | ||
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \ | ||
--build-arg GIT_REPO=${{ github.repository }} \ | ||
--build-arg GIT_TAG=${{ inputs.semVer }} \ | ||
--build-arg GIT_BRANCH=${{ github.ref }} \ | ||
--build-arg GIT_COMMIT=${{ github.sha }} \ | ||
--build-arg GITHUB_WORKFLOW=${{ github.workflow }} \ | ||
--build-arg GITHUB_RUN_ID=${{ github.run_id }} \ | ||
--build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \ | ||
--platform ${{ inputs.platform }} \ | ||
--pull \ | ||
--push \ | ||
. |
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