Skip to content

Commit

Permalink
update github action and dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
YuChia-Wei committed Nov 1, 2023
1 parent 7a1f8d3 commit 626327b
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
IMAGE_TAG: ${{github.tags}}
# IMAGE_TAG: 7.0-bullseye-slim

jobs:
build:
Expand All @@ -46,29 +44,32 @@ jobs:
- "6.0"
- "7.0"
os:
- alpine
- bullseye-slim
- "-bullseye-slim"
- "-bookworm-slim"
- ""

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
# - name: Install cosign
# if: github.event_name != 'pull_request'
# uses: sigstore/[email protected]
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: 'v2.1.1'

# Setup Docker buildx
# https://github.com/docker/setup-buildx-action
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2.5.0
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2.1.0
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -78,39 +79,41 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4.4.0
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ matrix.dotnet-version }}${{ matrix.os }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4.0.0
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: ./src
file: ./src/dotnet-${{ matrix.os }}.Dockerfile
file: ./src/dotnet-glibc.Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/yuchia-wei/otel-dotnet-auto-instrumentation:${{ matrix.dotnet-version }}-${{ matrix.os }}
# tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.dotnet-version }}-${{ matrix.os }}
# tags: ${{ steps.meta.outputs.tags }}
# tags: ${{ env.IMAGE_TAG }}
labels: |
${{ steps.meta.outputs.labels }}
tags: ghcr.io/yuchia-wei/otel-dotnet-auto-instrumentation:${{ matrix.dotnet-version }}${{ matrix.os }}
# tags: ghcr.io/yuchia-wei/otel-dotnet-auto-instrumentation:${{ matrix.dotnet-version }}-${{ matrix.os }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
dotnetVersion=${{ matrix.dotnet-version }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
BaseImageTag=${{ matrix.dotnet-version }}${{ matrix.os }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
# - name: Sign the published Docker image
# if: ${{ github.event_name != 'pull_request' }}
# env:
# COSIGN_EXPERIMENTAL: "true"
# # This step uses the identity token to provision an ephemeral certificate
# # against the sigstore community Fulcio instance.
# run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
113 changes: 113 additions & 0 deletions .github/workflows/docker-publish-musl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
# schedule:
# - cron: '39 2 * * *'
# push:
# branches: [ "main" ]
# # Publish semver tags as releases.
# tags: [ 'v*.*.*' ]
# pull_request:
# branches: [ "main" ]
push:
branches: [ "main" ]
paths-ignore:
- ./README.md
pull_request:
branches: [ "main" ]
paths-ignore:
- ./README.md

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
strategy:
matrix:
dotnet-version:
- "6.0"
- "7.0"

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: 'v2.1.1'

# Setup Docker buildx
# https://github.com/docker/setup-buildx-action
- name: Setup Docker buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ matrix.dotnet-version }}-alpine
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: ./src
file: ./src/dotnet-alpine.Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
# tags: ghcr.io/yuchia-wei/otel-dotnet-auto-instrumentation:${{ matrix.dotnet-version }}-alpine
labels: ${{ steps.meta.outputs.labels }}
build-args: dotnetVersion=${{ matrix.dotnet-version }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
32 changes: 0 additions & 32 deletions src/dotnet-bullseye-slim.Dockerfile

This file was deleted.

3 changes: 2 additions & 1 deletion src/dotnet.Dockerfile → src/dotnet-glibc.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG dotnetVersion=7.0
ARG BaseImageTag=${dotnetVersion}

FROM mcr.microsoft.com/dotnet/aspnet:${dotnetVersion} AS base
FROM mcr.microsoft.com/dotnet/aspnet:${BaseImageTag} AS base

# 處理 open telemetry dotnet auto instrumentation 套件
# 這邊將官方發布的 zip 檔案重新打包成 tar.gz 檔案,可避免在 docker build 時還要等待 unzip 工具的安裝
Expand Down

0 comments on commit 626327b

Please sign in to comment.