Skip to content

Commit

Permalink
minor code tweak and ci update (#13)
Browse files Browse the repository at this point in the history
* minor code tweak

* strip comments from JSON for jq

* ci IMAGE_NAME dynamic
  • Loading branch information
f2calv authored Jun 21, 2023
1 parent 079ed05 commit 0658ea2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
10 changes: 0 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update 'VARIANT' to pick a .NET Core version: 3.1, 6.0
// Append -bullseye or -focal to pin to an OS version.
"VARIANT": "7.0-bullseye",
// Options
"NODE_VERSION": "none"
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5001],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "sh . ./.devcontainer/postCreateCommand.sh",
"postStartCommand": "sh . ./.devcontainer/postStartCommand.sh",
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-dotnettools.csharp",
"ms-azuretools.vscode-docker",
Expand All @@ -28,7 +19,6 @@
]
}
},
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"docker-from-docker": "latest",
Expand Down
27 changes: 18 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ on:
branches: [main]
types: [opened, synchronize, reopened]

env:
IMAGE_NAME: multi-arch-container-dotnet

jobs:
build_app:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -69,7 +66,7 @@ jobs:

env:
REGISTRY: ghcr.io
#REPOSITORY: Note: set dynamically, i.e. github.repository_owner+IMAGE_NAME
REPOSITORY: ${{ github.repository }}
GIT_REPO: ${{ github.repository }}
GIT_TAG: ${{ needs.build_app.outputs.semVer }}
GIT_BRANCH: ${{ github.ref }}
Expand All @@ -81,7 +78,9 @@ jobs:
# fetch-depth: 0

- name: set vars (1 of 2)
run: echo "REPOSITORY=${{ github.repository_owner }}/$IMAGE_NAME" >> $GITHUB_ENV
run: |
IMAGE_NAME=$(echo $REPOSITORY | sed "s|${{ github.repository_owner }}\/||g")
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
- name: set vars (2 of 2)
if: github.ref != 'refs/heads/main' #non-default branch use a simplistic SemVer
Expand Down Expand Up @@ -142,7 +141,7 @@ jobs:

env:
REGISTRY: ghcr.io
#REPOSITORY: Note: set dynamically, i.e. github.repository_owner+IMAGE_NAME
#CHART_REPOSITORY: Note: set dynamically, i.e. github.repository_owner/charts/IMAGE_NAME
GIT_TAG: ${{ needs.build_app.outputs.semVer }}
HELM_EXPERIMENTAL_OCI: 1
HELM_VERSION_TO_INSTALL: 3.9.2 #Note: keep this version in sync inside the devcontainer
Expand All @@ -152,8 +151,18 @@ jobs:
with:
fetch-depth: 0 #Note: shallow clone may break git tag & ct lint...

- name: set vars
run: echo "REPOSITORY=${{ github.repository_owner }}/charts/$IMAGE_NAME" >> $GITHUB_ENV
- 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
Expand All @@ -162,7 +171,7 @@ jobs:

- name: helm registry login
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${REGISTRY}/${REPOSITORY} --username ${{ github.repository_owner }} --password-stdin
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${REGISTRY}/${CHART_REPOSITORY} --username ${{ github.repository_owner }} --password-stdin
- uses: actions/setup-python@v4
with:
Expand Down
14 changes: 7 additions & 7 deletions src/multi-arch-container-dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class AppSettings
{
public AppSettings()
{
GIT_REPO = Environment.GetEnvironmentVariable("GIT_REPO") ?? "n/a";
GIT_BRANCH = Environment.GetEnvironmentVariable("GIT_BRANCH") ?? "n/a";
GIT_COMMIT = Environment.GetEnvironmentVariable("GIT_COMMIT") ?? "n/a";
GIT_TAG = Environment.GetEnvironmentVariable("GIT_TAG") ?? "n/a";
GITHUB_WORKFLOW = Environment.GetEnvironmentVariable("GITHUB_WORKFLOW") ?? "n/a";
GITHUB_RUN_ID = Environment.GetEnvironmentVariable("GITHUB_RUN_ID") ?? "n/a";
GITHUB_RUN_NUMBER = Environment.GetEnvironmentVariable("GITHUB_RUN_NUMBER") ?? "n/a";
GIT_REPO = Environment.GetEnvironmentVariable(nameof(GIT_REPO)) ?? "n/a";
GIT_BRANCH = Environment.GetEnvironmentVariable(nameof(GIT_BRANCH)) ?? "n/a";
GIT_COMMIT = Environment.GetEnvironmentVariable(nameof(GIT_COMMIT)) ?? "n/a";
GIT_TAG = Environment.GetEnvironmentVariable(nameof(GIT_TAG)) ?? "n/a";
GITHUB_WORKFLOW = Environment.GetEnvironmentVariable(nameof(GITHUB_WORKFLOW)) ?? "n/a";
GITHUB_RUN_ID = Environment.GetEnvironmentVariable(nameof(GITHUB_RUN_ID)) ?? "n/a";
GITHUB_RUN_NUMBER = Environment.GetEnvironmentVariable(nameof(GITHUB_RUN_NUMBER)) ?? "n/a";
}
public string? GIT_REPO { get; }
public string? GIT_BRANCH { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"profiles": {
"multi-arch-container-dotnet": {
"commandName": "Project"
"commandName": "Project",
"environmentVariables": {
"GIT_REPO": "multi-arch-container-dotnet"
}
}
}
}

0 comments on commit 0658ea2

Please sign in to comment.