Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit caeddde

Browse files
committed
Changes to docker / github workflows
* Docker: Build & push multiarch images (arm, arm64, amd64) * GH workflows: Only create/upload releases on tag (semver -> v0.1.2)
1 parent f5f1b75 commit caeddde

File tree

3 files changed

+78
-21
lines changed

3 files changed

+78
-21
lines changed

.github/workflows/Docker.yml

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,68 @@
11
name: docker
22

3-
on: [push]
3+
on:
4+
pull_request:
5+
branches: master
6+
push:
7+
branches: master
8+
tags:
9+
- v*
410

511
jobs:
6-
push-image:
12+
buildx:
13+
runs-on: ubuntu-latest
14+
steps:
15+
-
16+
name: Checkout
17+
uses: actions/checkout@v2
18+
-
19+
name: Prepare
20+
id: prepare
21+
run: |
22+
DOCKER_IMAGE=storedev/store-bot
23+
DOCKER_PLATFORMS=linux/amd64,linux/arm/v7,linux/arm64
24+
VERSION=edge
725
8-
runs-on: windows-latest
26+
if [[ $GITHUB_REF == refs/tags/* ]]; then
27+
VERSION=${GITHUB_REF#refs/tags/v}
28+
fi
29+
if [ "${{ github.event_name }}" = "schedule" ]; then
30+
VERSION=nightly
31+
fi
932
10-
steps:
11-
- uses: actions/checkout@v2
12-
- run: |
13-
docker login --username ${{ secrets.DOCKER_USERNAME }} --password "${{ secrets.DOCKER_PASSWORD }}"
14-
docker build -t storedev/store-bot .
15-
docker tag storedev/store-bot storedev/store-bot:${{ github.sha }}
16-
docker tag storedev/store-bot storedev/store-bot:Latest
17-
docker push storedev/store-bot
33+
TAGS="--tag ${DOCKER_IMAGE}:${VERSION}"
34+
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
35+
TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest"
36+
fi
37+
38+
echo ::set-output name=docker_image::${DOCKER_IMAGE}
39+
echo ::set-output name=version::${VERSION}
40+
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
41+
--build-arg VERSION=${VERSION} \
42+
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
43+
--build-arg VCS_REF=${GITHUB_SHA::8} \
44+
${TAGS} --file ./Dockerfile .
45+
-
46+
name: Set up Docker Buildx
47+
uses: crazy-max/ghaction-docker-buildx@v3
48+
-
49+
name: Docker Buildx (build)
50+
run: |
51+
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
52+
-
53+
name: Login to DockerHub
54+
if: success() && github.event_name != 'pull_request'
55+
uses: docker/login-action@v1
56+
with:
57+
username: ${{ secrets.DOCKER_USERNAME }}
58+
password: ${{ secrets.DOCKER_PASSWORD }}
59+
-
60+
name: Docker Buildx (push)
61+
if: success() && github.event_name != 'pull_request'
62+
run: |
63+
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }}
64+
-
65+
name: Inspect image
66+
if: always() && github.event_name != 'pull_request'
67+
run: |
68+
docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: build
22

3-
on: [push]
3+
on: ['push', 'pull_request']
44

55
jobs:
66
build:
77

8-
runs-on: windows-latest
8+
runs-on: ubuntu-latest
99

1010
steps:
1111
- uses: actions/checkout@v2
@@ -20,28 +20,34 @@ jobs:
2020
- name: Upload artifact
2121
uses: actions/upload-artifact@v2
2222
with:
23-
name: storebot.zip-${{ github.sha }}
23+
name: storebot-${{ github.sha }}.zip
2424
path: bin/Release/netcoreapp3.1
25+
- name: Get the version tag
26+
id: get_tag
27+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
2528
- name: Generate zip for release
26-
run: tar.exe -a -c -f Storebot-${{ github.sha }}.zip bin\Release\netcoreapp3.1
29+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
30+
run: zip -j Storebot-${{ steps.get_tag.outputs.VERSION }}.zip ./bin/Release/netcoreapp3.1/* ./README.md ./config.json
2731
- name: create release
32+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
2833
id: create_release
2934
uses: actions/create-release@v1
3035
env:
3136
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3237
with:
33-
tag_name: V${{ github.run_number }}
34-
release_name: Release V${{ github.run_number }}
38+
tag_name: ${{ steps.get_tag.outputs.VERSION }}
39+
release_name: Release ${{ steps.get_tag.outputs.VERSION }}
3540
draft: false
3641
prerelease: false
3742
- name: Upload Release Asset
43+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
3844
id: upload-release-asset
3945
uses: actions/upload-release-asset@v1
4046
env:
4147
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4248
with:
4349
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
44-
asset_path: ./Storebot-${{ github.sha }}.zip
45-
asset_name: Storebot-${{ github.sha }}.zip
50+
asset_path: ./Storebot-${{ steps.get_tag.outputs.VERSION }}.zip
51+
asset_name: Storebot-${{ steps.get_tag.outputs.VERSION }}.zip
4652
asset_content_type: application/zip
4753

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://hub.docker.com/_/microsoft-dotnet-core
2-
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
2+
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build
33
WORKDIR /source
44

55
# copy csproj and restore as distinct layers
@@ -14,7 +14,7 @@ WORKDIR /source
1414
RUN dotnet publish -c release -o /app --no-restore
1515

1616
# final stage/image
17-
FROM mcr.microsoft.com/dotnet/core/runtime:3.1
17+
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-alpine
1818
WORKDIR /app
1919
COPY --from=build /app ./
2020
ENTRYPOINT ["dotnet", "StoreBot.dll"]

0 commit comments

Comments
 (0)