mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-15 09:50:20 +08:00
try new build action
This commit is contained in:
parent
7029fd48f1
commit
b72c69fc8e
163
.github/workflows/docker-publish.yml
vendored
163
.github/workflows/docker-publish.yml
vendored
@ -23,33 +23,57 @@ env:
|
|||||||
IMAGE_NAME: ${{ github.repository }}
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
# This is used to complete the identity challenge
|
|
||||||
# with sigstore/fulcio when running outside of PRs.
|
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
id: test
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64
|
||||||
|
cache-from: type=gha,scope=buildkit-x64
|
||||||
|
pull: true
|
||||||
|
cache-to: type=gha,mode=max,scope=buildkit-x64
|
||||||
|
target: test
|
||||||
|
|
||||||
|
build:
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
platform: [linux/amd64, linux/arm64]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# Install the cosign tool except on PR
|
# Install the cosign tool except on PR
|
||||||
# https://github.com/sigstore/cosign-installer
|
|
||||||
- name: Install cosign
|
- name: Install cosign
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: sigstore/cosign-installer@v3
|
uses: sigstore/cosign-installer@v3
|
||||||
|
|
||||||
# Set up BuildKit Docker container builder to be able to build
|
# Set up BuildKit Docker container builder
|
||||||
# multi-platform images and export cache
|
|
||||||
# https://github.com/docker/setup-buildx-action
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
# Login against a Docker registry except on PR
|
# Login against a Docker registry except on PR
|
||||||
# https://github.com/docker/login-action
|
|
||||||
- name: Log into registry ${{ env.REGISTRY }}
|
- name: Log into registry ${{ env.REGISTRY }}
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
@ -59,7 +83,6 @@ jobs:
|
|||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
# Extract metadata (tags, labels) for Docker
|
# Extract metadata (tags, labels) for Docker
|
||||||
# https://github.com/docker/metadata-action
|
|
||||||
- name: Extract Docker metadata
|
- name: Extract Docker metadata
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
@ -73,68 +96,94 @@ jobs:
|
|||||||
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
|
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
- name: Test
|
# Get platform specific variables
|
||||||
id: test
|
- name: Set platform-specific variables
|
||||||
uses: docker/build-push-action@v6
|
id: platform-vars
|
||||||
with:
|
run: |
|
||||||
context: .
|
PLATFORM="${{ matrix.platform }}"
|
||||||
platforms: linux/amd64
|
PLATFORM_SUFFIX="${PLATFORM//\//-}"
|
||||||
cache-from: type=gha,scope=buildkit-x64
|
echo "platform_suffix=${PLATFORM_SUFFIX}" >> $GITHUB_OUTPUT
|
||||||
pull: true
|
echo "cache_scope=buildkit-${PLATFORM_SUFFIX}" >> $GITHUB_OUTPUT
|
||||||
cache-to: type=gha,mode=max,scope=buildkit-x64
|
|
||||||
target: test
|
|
||||||
|
|
||||||
- name: Build and push Docker image for arm64
|
# Build and push Docker image with platform-specific tag
|
||||||
id: build-and-push-arm64
|
- name: Build and push Docker image
|
||||||
|
id: build-and-push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
pull: true
|
pull: true
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}-${{ steps.platform-vars.outputs.platform_suffix }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
platforms: linux/arm64
|
platforms: ${{ matrix.platform }}
|
||||||
cache-from: type=gha,scope=buildkit-arm64
|
cache-from: type=gha,scope=${{ steps.platform-vars.outputs.cache_scope }}
|
||||||
cache-to: type=gha,mode=max,scope=buildkit-arm64
|
cache-to: type=gha,mode=max,scope=${{ steps.platform-vars.outputs.cache_scope }}
|
||||||
build-args: GITHUB_BUILD=true,VERSION=${{ github.ref_name }}
|
build-args: GITHUB_BUILD=true,VERSION=${{ github.ref_name }}
|
||||||
|
|
||||||
# Sign the resulting Docker image digest except on PRs.
|
# Sign the platform specific image
|
||||||
# This will only write to the public Rekor transparency log when the Docker
|
- name: Sign the published Docker image
|
||||||
# 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 for arm64
|
|
||||||
if: ${{ github.event_name != 'pull_request' }}
|
if: ${{ github.event_name != 'pull_request' }}
|
||||||
env:
|
env:
|
||||||
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
|
TAGS: ${{ steps.meta.outputs.tags }}-${{ steps.platform-vars.outputs.platform_suffix }}
|
||||||
TAGS: ${{ steps.meta.outputs.tags }}
|
DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
||||||
DIGEST: ${{ steps.build-and-push-arm64.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}
|
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
|
||||||
|
|
||||||
# Build and push Docker image with Buildx (don't push on PR)
|
merge:
|
||||||
# https://github.com/docker/build-push-action
|
needs: build
|
||||||
- name: Build and push Docker image for x64
|
runs-on: ubuntu-latest
|
||||||
id: build-and-push-x64
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/build-push-action@v6
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log into registry ${{ env.REGISTRY }}
|
||||||
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
context: .
|
registry: ${{ env.REGISTRY }}
|
||||||
pull: true
|
username: ${{ github.actor }}
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
platforms: linux/amd64
|
|
||||||
cache-from: type=gha,scope=buildkit-x64
|
|
||||||
cache-to: type=gha,mode=max,scope=buildkit-x64
|
|
||||||
build-args: GITHUB_BUILD=true,VERSION=${{ github.ref_name }}
|
|
||||||
|
|
||||||
- name: Sign the published Docker image for x64
|
- name: Extract Docker metadata
|
||||||
if: ${{ github.event_name != 'pull_request' }}
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
|
- name: Install cosign
|
||||||
|
uses: sigstore/cosign-installer@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Create and push manifest
|
||||||
|
run: |
|
||||||
|
TAGS="${{ steps.meta.outputs.tags }}"
|
||||||
|
for TAG in $TAGS; do
|
||||||
|
# Create manifest list and push it
|
||||||
|
docker buildx imagetools create -t $TAG \
|
||||||
|
$TAG-linux-amd64 \
|
||||||
|
$TAG-linux-arm64
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Install cosign
|
||||||
|
uses: sigstore/cosign-installer@v3
|
||||||
|
|
||||||
|
- name: Sign the manifest
|
||||||
env:
|
env:
|
||||||
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
|
|
||||||
TAGS: ${{ steps.meta.outputs.tags }}
|
TAGS: ${{ steps.meta.outputs.tags }}
|
||||||
DIGEST: ${{ steps.build-and-push-x64.outputs.digest }}
|
run: |
|
||||||
# This step uses the identity token to provision an ephemeral certificate
|
for TAG in $TAGS; do
|
||||||
# against the sigstore community Fulcio instance.
|
cosign sign --yes $TAG
|
||||||
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user