Skip to content

Commit

Permalink
dotnet7 & misc updates (#4)
Browse files Browse the repository at this point in the history
* rename

* lowercase

* boilerplate

* ci improvements

* ci tweak

* added license

* debug comment tweak

* updated to .net 7

* update action

* tweaks

* add dev container

* docs

* tidy pipeline

* test

* tidy

* doc update

* wf tidy

* rename

* rename

* renaming

* fixes

* renames

* rename

* comment

* improve devcontainer

* renaming

* updates

* comment

* rename

* fix case

* update readme

* readme tweaks

* updates

* updates

* addedlaunch

* updates

* updates

* docs

* fix typo

* readme update

Co-authored-by: Azure DevOps CI <[email protected]>
  • Loading branch information
f2calv and Azure DevOps CI authored Dec 11, 2022
1 parent 3f72b53 commit 798e280
Show file tree
Hide file tree
Showing 37 changed files with 490 additions and 323 deletions.
18 changes: 18 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/dotnet/.devcontainer/base.Dockerfile

ARG VARIANT="7.0-bullseye-slim"
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 18, 16, 14
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

#add extra tools - see https://github.com/natemcmaster/dotnet-tools
RUN dotnet tool update -g GitVersion.Tool
42 changes: 42 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "C# (.NET)",
"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",
"ms-vscode.powershell",
"ms-vscode.azurecli"
]
}
},
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"docker-from-docker": "latest",
"kubectl-helm-minikube": {
"version": "latest",
"helm": "3.9.2",
"minikube": "none"
},
"powershell": "latest"
}
}
6 changes: 6 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

echo "postCreateCommand.sh"
echo "--------------------"

sudo chmod +x .devcontainer/postStartCommand.sh
12 changes: 12 additions & 0 deletions .devcontainer/postStartCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

echo "postStartCommand.sh"
echo "-------------------"

sudo apt-get update
sudo apt-get upgrade -y

rustup --version
rustc --version

echo "Done"
38 changes: 9 additions & 29 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
**/*.ps1
**/.scripts
**/.pipelines
**/.github
# first ignore everything
*
# explictly add exceptions for required files/paths
!src/**/*.cs
!**/*.csproj
!**/*.sln
!NuGet.config
!global.json
!Directory.build.props
110 changes: 35 additions & 75 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ name: ci

on:
workflow_dispatch:
# inputs:
# BuildConfiguration:
# description: Build Configuration
# required: true
# default: Release
push:
branches-ignore:
- "preview/**"
paths-ignore:
# - .azure-pipelines
# - .pipelines
# - .github
# - .scripts
# - .charts
# - LICENSE
- LICENSE
- README.md
pull_request:
branches: [main]
types: [opened, synchronize, reopened]

env:
IMAGE_NAME: dotnetmultiarchapp
IMAGE_NAME: multi-arch-container-dotnet

jobs:
build_app:
Expand All @@ -28,35 +26,33 @@ jobs:
FullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: .NET 6.x SDK
uses: actions/setup-dotnet@v1
- name: .NET 7.x SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: gitversion
shell: pwsh
id: gitversion
run: |
dotnet tool update -g GitVersion.Tool
$GitVersion = dotnet-gitversion ${{ github.workspace }} /nofetch | ConvertFrom-Json
echo "SemVer=$($GitVersion.SemVer)"
echo "::set-output name=SemVer::$($GitVersion.SemVer)"
echo "FullSemVer=$($GitVersion.FullSemVer)"
echo "::set-output name=FullSemVer::$($GitVersion.FullSemVer)"
Write-Host "SemVer=$($GitVersion.SemVer)"
echo "SemVer=$($GitVersion.SemVer)" >> $env:GITHUB_OUTPUT
Write-Host "FullSemVer=$($GitVersion.FullSemVer)"
echo "FullSemVer=$($GitVersion.FullSemVer)" >> $env:GITHUB_OUTPUT
- name: dotnet restore
run: dotnet restore --verbosity minimal --configfile NuGet.config
if: false #disable during debug

- name: dotnet build
run: dotnet build -c Release --nologo --no-restore -p:Version='${{ steps.gitversion.outputs.FullSemVer }}' -p:SourceRevisionId=${{ github.sha }}
if: false #disable during debug

#run dotnet test here...
#TODO: could run dotnet test here, etc...

build_image:
runs-on: ubuntu-latest
Expand All @@ -76,40 +72,26 @@ jobs:
GIT_COMMIT: ${{ github.sha }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# with:
# fetch-depth: 0

- name: set vars (1 of 2)
run: echo "REPOSITORY=${{ github.repository_owner }}/$IMAGE_NAME" >> $GITHUB_ENV

- name: set vars (2 of 2)
if: github.ref != 'refs/heads/main' #non-default branch use a more verbose SemVer
if: github.ref != 'refs/heads/main' #non-default branch use a simplistic SemVer
run: echo "GIT_TAG=dev" >> $GITHUB_ENV

- name: set vars (pwsh)
shell: pwsh
run: echo "REPOSITORY=${{ github.repository_owner }}/$IMAGE_NAME" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
if: false #debug

- name: github context json
run: echo '${{ toJSON(github) }}'
if: false #debug

- name: github context json (pwsh)
shell: pwsh
run: Write-Host '${{ toJSON(github) }}'
if: false #debug

- name: docker login ${{ env.REGISTRY }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin

- name: docker build
if: github.ref != 'refs/heads/main'
#if: github.ref != 'refs/heads/main'
if: false #disabled as we now use 'docker buildx build'
run: |
docker build \
-t $REGISTRY/$REPOSITORY:$GIT_TAG \
-f src/$IMAGE_NAME/Dockerfile \
--label "GITHUB_RUN_ID=${{ github.run_id }}" \
--label "IMAGE_NAME=$IMAGE_NAME" \
--build-arg GIT_REPO=$GIT_REPO \
Expand All @@ -120,45 +102,23 @@ jobs:
--build-arg GITHUB_RUN_ID=${{ github.run_id }} \
--build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \
--pull \
.
- name: docker build (pwsh)
shell: pwsh
if: false #disabled as we now use 'docker buildx build'
run: |
docker build `
-t "$($env:REGISTRY)/$($env:REPOSITORY):$($env:GIT_TAG)" `
-f "src/$($env:IMAGE_NAME)/Dockerfile" `
--label "GITHUB_RUN_ID=${{ github.run_id }}" `
--label "IMAGE_NAME=$($env:IMAGE_NAME)" `
--build-arg GIT_REPO=$($env:GIT_REPO) `
--build-arg GIT_TAG=$($env:GIT_TAG) `
--build-arg GIT_BRANCH=$($env:GIT_BRANCH) `
--build-arg GIT_COMMIT=$($env:GIT_COMMIT) `
--build-arg GITHUB_WORKFLOW=${{ github.workflow }} `
--build-arg GITHUB_RUN_ID=${{ github.run_id }} `
--build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} `
--pull `
--push \
.
- name: docker push
if: github.ref != 'refs/heads/main'
run: docker push $REGISTRY/$REPOSITORY:$GIT_TAG

- name: docker push latest
if: github.ref != 'refs/heads/main'
#if: github.ref != 'refs/heads/main'
if: false #disabled as we now use 'docker buildx build'
run: |
docker tag $REGISTRY/$REPOSITORY:$GIT_TAG $REGISTRY/$REPOSITORY
docker push $REGISTRY/$REPOSITORY:$GIT_TAG
docker push $REGISTRY/$REPOSITORY
- name: docker buildx build
if: github.ref == 'refs/heads/main'
#if: github.ref == 'refs/heads/main'
run: |
docker buildx create --name multiarchtest --use
docker buildx build \
-t $REGISTRY/$REPOSITORY:$GIT_TAG \
-t $REGISTRY/$REPOSITORY:latest \
-f src/$IMAGE_NAME/Dockerfile.multiarch \
--label "GITHUB_RUN_ID=${{ github.run_id }}" \
--label "IMAGE_NAME=$IMAGE_NAME" \
--build-arg GIT_REPO=$GIT_REPO \
Expand All @@ -169,8 +129,8 @@ jobs:
--build-arg GITHUB_RUN_ID=${{ github.run_id }} \
--build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--push \
--pull \
--push \
.
push_chart:
Expand All @@ -179,40 +139,40 @@ jobs:
if: github.ref == 'refs/heads/main'

permissions:
packages: write #for pushing container image
packages: write #for pushing helm package
contents: write #for creating releases/tags

env:
REGISTRY: ghcr.io
#REPOSITORY: Note: set dynamically, i.e. github.repository_owner+IMAGE_NAME
GIT_TAG: ${{ needs.build_app.outputs.SemVer }}
HELM_EXPERIMENTAL_OCI: 1
HELM_VERSION_TO_INSTALL: 3.8.1
HELM_VERSION_TO_INSTALL: 3.9.2 #Note: keep this version in sync inside the devcontainer

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0 #Note: shallow clone may break git tag & ct lint...

- name: set vars
run: echo "REPOSITORY=${{ github.repository_owner }}/$IMAGE_NAME" >> $GITHUB_ENV

- name: install helm
uses: azure/setup-helm@v1
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}/${REPOSITORY} --username ${{ github.repository_owner }} --password-stdin
- uses: actions/setup-python@v2
- 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.2.1
uses: helm/chart-testing-action@v2
if: false #not implemented/working yet

- name: chart-testing (run list-changed)
Expand All @@ -229,7 +189,7 @@ jobs:
if: false #not implemented/working yet

- name: create kind cluster
uses: helm/kind-action@v1.2.0
uses: helm/kind-action@v1
#if: steps.list-changed.outputs.changed == 'true'
if: false #not implemented/working yet

Expand All @@ -245,7 +205,7 @@ jobs:
run: |
helm push ${{ github.workspace }}/artifacts/$IMAGE_NAME-0.1.0.tgz oci://ghcr.io/${{ github.repository_owner }}
- name: create-release $GIT_TAG
- name: create release $GIT_TAG
uses: softprops/action-gh-release@v1
if: github.ref == 'refs/heads/main'
with:
Expand Down
4 changes: 2 additions & 2 deletions .scripts/Invoke-Setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ $ErrorActionPreference = "Stop"

& "docker" login

$IMAGE_NAME = "dotnetmultiarchapp"
$REPO_ROOT = git rev-parse --show-toplevel
$IMAGE_NAME = "multi-arch-container-dotnet"
$REPOSITORY = "$DOCKERHUB_USERNAME/$IMAGE_NAME"
$REPO_ROOT = git rev-parse --show-toplevel
$GIT_REPO = $REPO_ROOT | Split-Path -Leaf
$GIT_TAG = "dev"
$GIT_BRANCH = $(git branch --show-current)
Expand Down
Loading

0 comments on commit 798e280

Please sign in to comment.