Skip to content

Upload Image

Upload Image #125

Workflow file for this run

name: Upload Image
on:
workflow_dispatch: {}
schedule:
- cron: "0 0 * * 0"
release:
types: [published]
permissions: read-all
jobs:
build-specific-architecture:
if: ${{ github.repository == 'chaos-mesh/chaos-mesh' }}
permissions:
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#authenticating-to-package-registries-on-github
packages: write
strategy:
matrix:
arch: [amd64, arm64]
image:
[chaos-daemon, chaos-mesh, chaos-dashboard, chaos-kernel, chaos-dlv]
outputs:
image_tag: ${{ steps.image_tag.outputs.image_tag }}
runs-on: ${{ fromJson('{"amd64":"ubuntu-20.04", "arm64":["self-hosted", "Linux", "ARM64"]}')[matrix.arch] }}
steps:
- uses: actions/checkout@v4
with:
# It requires all the tags and branches to generate the correct GitVersion with `hack/version.sh`.
fetch-depth: 0
- name: Extract Image Tag
id: image_tag
shell: bash
run: |
IMAGE_TAG=${GITHUB_REF##*/}
if [ "${IMAGE_TAG}" = "master" ] ; then
IMAGE_TAG=latest;
fi
echo "::set-output name=image_tag::$(echo $IMAGE_TAG)"
- name: Login to GitHub Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Chaos Mesh
env:
IMAGE_TAG: ${{ steps.image_tag.outputs.image_tag }}
ARCH: ${{ matrix.arch }}
IMAGE: ${{ matrix.image }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
if [ "${IMAGE}" = "chaos-dashboard" ]; then
UI=1
else
UI=0
fi
# ${VAR,,} convert VAR to lower case
make -B \
TARGET_PLATFORM=$ARCH \
IMAGE_TAG=$IMAGE_TAG-$ARCH \
IMAGE_DEV_ENV_BUILD=1 \
IMAGE_BUILD_ENV_BUILD=1 \
UI=$UI \
image-$IMAGE
- name: Upload Chaos Mesh
env:
IMAGE_TAG: ${{ steps.image_tag.outputs.image_tag }}
ARCH: ${{ matrix.arch }}
IMAGE: ${{ matrix.image }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
# ${VAR,,} convert VAR to lower case
docker push ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG-$ARCH
upload-manifest:
needs: build-specific-architecture
runs-on: ubuntu-20.04
permissions:
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#authenticating-to-package-registries-on-github
packages: write
strategy:
matrix:
image:
[chaos-daemon, chaos-mesh, chaos-dashboard, chaos-kernel, chaos-dlv]
env:
IMAGE_TAG: ${{ needs.build-specific-architecture.outputs.image_tag }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
steps:
- name: Create the manifest list
env:
IMAGE: ${{ matrix.image }}
run: |
# ${VAR,,} convert VAR to lower case
docker manifest create ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG \
ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG-amd64 \
ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG-arm64
docker manifest annotate ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG \
ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG-amd64 \
--os linux --arch amd64
docker manifest annotate ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG \
ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG-arm64 \
--os linux --arch arm64
- name: Login to GitHub Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push the manifest list
env:
IMAGE: ${{ matrix.image }}
run: |
# ${VAR,,} convert VAR to lower case
docker manifest push ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$IMAGE:$IMAGE_TAG
sign:
needs:
- build-specific-architecture
- upload-manifest
if: needs.build-specific-architecture.outputs.image_tag != 'latest'
runs-on: ubuntu-20.04
permissions:
contents: write # Need to upload files to the related release.
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#authenticating-to-package-registries-on-github
packages: write
env:
IMAGE_TAG: ${{ needs.build-specific-architecture.outputs.image_tag }}
steps:
- name: Install cosign
uses: sigstore/cosign-installer@main
with:
cosign-release: "v1.13.1"
- name: Login to GitHub Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Sign Chaos Mesh Container images
env:
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
run: |
cosign sign --key env://COSIGN_PRIVATE_KEY ghcr.io/chaos-mesh/chaos-mesh:$IMAGE_TAG --output-signature ghcr.io-chaos-mesh-chaos-mesh-$IMAGE_TAG.sig
cosign sign --key env://COSIGN_PRIVATE_KEY ghcr.io/chaos-mesh/chaos-daemon:$IMAGE_TAG --output-signature ghcr.io-chaos-mesh-chaos-daemon-$IMAGE_TAG.sig
cosign sign --key env://COSIGN_PRIVATE_KEY ghcr.io/chaos-mesh/chaos-dashboard:$IMAGE_TAG --output-signature ghcr.io-chaos-mesh-chaos-dashboard-$IMAGE_TAG.sig
cosign sign --key env://COSIGN_PRIVATE_KEY ghcr.io/chaos-mesh/chaos-kernel:$IMAGE_TAG --output-signature ghcr.io-chaos-mesh-chaos-kernel-$IMAGE_TAG.sig
cosign public-key --key env://COSIGN_PRIVATE_KEY > cosign.pub
- name: Upload cosign.pub and sigs
uses: softprops/action-gh-release@v1
with:
files: |
cosign.pub
ghcr.io-chaos-mesh-chaos-mesh-${{ needs.build-specific-architecture.outputs.image_tag }}.sig
ghcr.io-chaos-mesh-chaos-daemon-${{ needs.build-specific-architecture.outputs.image_tag }}.sig
ghcr.io-chaos-mesh-chaos-dashboard-${{ needs.build-specific-architecture.outputs.image_tag }}.sig
ghcr.io-chaos-mesh-chaos-kernel-${{ needs.build-specific-architecture.outputs.image_tag }}.sig
sbom:
needs: build-specific-architecture
if: needs.build-specific-architecture.outputs.image_tag != 'latest'
runs-on: ubuntu-20.04
permissions:
contents: write # Need to upload files to the related release.
env:
IMAGE_TAG: ${{ needs.build-specific-architecture.outputs.image_tag }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: "go.mod"
- name: Install bom
run: go install sigs.k8s.io/bom/cmd/bom@latest
- name: Generate SBOM
run: bom generate -n https://chaos-mesh.org/chaos-mesh.spdx -o chaos-mesh-$IMAGE_TAG-sbom.spdx .
- name: Upload SBOM
uses: softprops/action-gh-release@v1
with:
files: chaos-mesh-${{ needs.build-specific-architecture.outputs.image_tag }}-sbom.spdx