Skip to content

Commit

Permalink
Update docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
thohng committed Feb 3, 2022
1 parent 921f206 commit 1cf2d90
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"minver-cli": {
"version": "3.0.0-rc.1",
"commands": [
"minver"
]
}
}
}
25 changes: 25 additions & 0 deletions .docker-linux/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.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
8 changes: 8 additions & 0 deletions .docker-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG ASPNET_IMAGE=mcr.microsoft.com/dotnet/aspnet:6.0-alpine
FROM ${ASPNET_IMAGE}
WORKDIR /app
EXPOSE 80
RUN apk update && apk add --no-cache ca-certificates tzdata
ENV TZ=UTC
COPY app .
ENTRYPOINT ["dotnet", "EchoServiceApi.dll"]
25 changes: 25 additions & 0 deletions .docker-windows/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.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
6 changes: 6 additions & 0 deletions .docker-windows/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG ASPNET_IMAGE=mcr.microsoft.com/dotnet/aspnet:6.0-nanoserver-1809
FROM ${ASPNET_IMAGE}
WORKDIR /app
EXPOSE 80
COPY app .
ENTRYPOINT ["dotnet", "EchoServiceApi.dll"]
56 changes: 52 additions & 4 deletions .github/workflows/aspnet-core.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: ASP.NET Core
name: ASP.NETCore 6

on:
push:
branches: [main]
branches: ["main", "dev*"]
tags: ["*.*.*"]
pull_request:
branches: [main]
Expand All @@ -19,15 +19,63 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .NET Core 6.0.x
- name: Setup .NET Core 6.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: "6.0.x"
- name: dotnet info
run: dotnet --info
- name: Install dotnet tool
run: dotnet tool restore
- name: MinVer
id: minver
run: echo "::set-output name=version::$(dotnet minver)"
- name: Docker meta
if: ${{ success() && github.event_name != 'pull_request' && runner.os == 'Linux' }}
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ secrets.DOCKER_HUB_REPOS }}
netlah/echo-service-api
tags: |
type=raw,enable=true,priority=999,prefix=,suffix=,value=${{ steps.minver.outputs.version }}
type=ref,event=branch,priority=600
type=sha,enable=true,priority=500,prefix=sha-,suffix=,format=short
type=match,enable=true,priority=900,prefix=,suffix=,pattern=^(\d+\.\d+(\.\d+)?(-.+)?)$,group=1
type=match,enable=true,priority=880,prefix=,suffix=,pattern=^(\d+\.\d+(\.\d+))?(-.+)?$,group=1
type=match,enable=true,priority=870,prefix=,suffix=,pattern=^(\d+\.\d+)(\.\d+)?(-.+)?$,group=1
type=match,enable=true,priority=860,prefix=,suffix=,pattern=^(\d+)\.\d+(\.\d+)?(-.+)?$,group=1
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test -c Release --no-build --verbosity normal
- name: Publish
run: dotnet publish EchoServiceApi -c Release -o ./artifacts/echoServiceApi/ --no-build
run: dotnet publish EchoServiceApi -c Release --no-build -o artifacts/app
- name: Copy Dockerfile
if: ${{ success() && github.event_name != 'pull_request' && runner.os == 'Linux' }}
run: cp .docker-linux/* artifacts/
- name: Set up Docker Buildx
if: ${{ success() && github.event_name != 'pull_request' && runner.os == 'Linux' }}
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
if: ${{ success() && github.event_name != 'pull_request' && runner.os == 'Linux' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push
if: ${{ success() && github.event_name != 'pull_request' && runner.os == 'Linux' }}
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./artifacts
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
if: ${{ success() && github.event_name != 'pull_request' && runner.os == 'Linux' }}
run: echo ${{ steps.docker_build.outputs.digest }}
1 change: 1 addition & 0 deletions EchoServiceApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.azure\pipelines\azure-pipelines.yml = .azure\pipelines\azure-pipelines.yml
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
.docker-linux\Dockerfile = .docker-linux\Dockerfile
README.md = README.md
EndProjectSection
EndProject
Expand Down

0 comments on commit 1cf2d90

Please sign in to comment.