mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 09:23:25 +00:00
Revise the workflow of publish dokcer images
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
5f28b48ca4
commit
0ddc1bb2d2
104
.github/workflows/publish_docker_images.yml
vendored
104
.github/workflows/publish_docker_images.yml
vendored
@ -9,101 +9,89 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
publish_osdk_image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
with:
|
|
||||||
driver: docker
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- name: Prepare for Docker build and push
|
||||||
- name: Check if Docker image exists
|
id: prepare-for-docker-build-and-push
|
||||||
id: check-images
|
|
||||||
run: |
|
run: |
|
||||||
IMAGE_TAG=$(cat DOCKER_IMAGE_VERSION)
|
./tools/github_workflows/prepare_for_docker_build_and_push.sh ${{ secrets.DOCKERHUB_USERNAME }} ${{ secrets.DOCKERHUB_TOKEN }} osdk
|
||||||
if docker manifest inspect asterinas/osdk:${IMAGE_TAG} > /dev/null 2>&1; then
|
|
||||||
echo "osdk_image_exists=true" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "osdk_image_exists=false" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
if docker manifest inspect asterinas/osdk:${IMAGE_TAG}-tdx > /dev/null 2>&1; then
|
|
||||||
echo "osdk_tdx_image_exists=true" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "osdk_tdx_image_exists=false" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
if docker manifest inspect asterinas/asterinas:${IMAGE_TAG} > /dev/null 2>&1; then
|
|
||||||
echo "asterinas_image_exists=true" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "asterinas_image_exists=false" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
if docker manifest inspect asterinas/asterinas:${IMAGE_TAG}-tdx > /dev/null 2>&1; then
|
|
||||||
echo "asterinas_tdx_image_exists=true" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "asterinas_tdx_image_exists=false" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Fetch versions in the repo
|
|
||||||
id: fetch-versions
|
|
||||||
run: |
|
|
||||||
ASTER_VERSION=$(cat DOCKER_IMAGE_VERSION)
|
|
||||||
RUST_VERSION=$(grep -m1 -o 'nightly-[0-9]\+-[0-9]\+-[0-9]\+' rust-toolchain.toml)
|
|
||||||
echo "aster_version=$ASTER_VERSION" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "rust_version=$RUST_VERSION" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Build and push the OSDK development image
|
- name: Build and push the OSDK development image
|
||||||
if: env.osdk_image_exists == 'false'
|
if: ${{ steps.prepare-for-docker-build-and-push.outputs.is_existed == 'false' }}
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./osdk/tools/docker/Dockerfile
|
file: ./osdk/tools/docker/Dockerfile
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
load: true
|
tags: asterinas/osdk:${{ steps.prepare-for-docker-build-and-push.outputs.image_version }}
|
||||||
tags: asterinas/osdk:${{ steps.fetch-versions.outputs.aster_version }}
|
|
||||||
build-args: |
|
build-args: |
|
||||||
ASTER_RUST_VERSION=${{ steps.fetch-versions.outputs.rust_version }}
|
ASTER_RUST_VERSION=${{ steps.prepare-for-docker-build-and-push.outputs.rust_version }}
|
||||||
|
|
||||||
|
publish_osdk_tdx_image:
|
||||||
|
needs: publish_osdk_image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Prepare for Docker build and push
|
||||||
|
id: prepare-for-docker-build-and-push
|
||||||
|
run: |
|
||||||
|
./tools/github_workflows/prepare_for_docker_build_and_push.sh ${{ secrets.DOCKERHUB_USERNAME }} ${{ secrets.DOCKERHUB_TOKEN }} osdk-tdx
|
||||||
|
|
||||||
- name: Build and push the OSDK development image for Intel TDX
|
- name: Build and push the OSDK development image for Intel TDX
|
||||||
if: env.osdk_tdx_image_exists == 'false'
|
if: ${{ steps.prepare-for-docker-build-and-push.outputs.is_existed == 'false' }}
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./osdk/tools/docker/tdx/Dockerfile
|
file: ./osdk/tools/docker/tdx/Dockerfile
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: asterinas/osdk:${{ steps.fetch-versions.outputs.aster_version }}-tdx
|
tags: asterinas/osdk:${{ steps.prepare-for-docker-build-and-push.outputs.image_version }}-tdx
|
||||||
build-args: |
|
build-args: |
|
||||||
BASE_VERSION=${{ steps.fetch-versions.outputs.aster_version }}
|
BASE_VERSION=${{ steps.prepare-for-docker-build-and-push.outputs.image_version }}
|
||||||
|
|
||||||
|
publish_asterinas_image:
|
||||||
|
needs: publish_osdk_image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Prepare for Docker build and push
|
||||||
|
id: prepare-for-docker-build-and-push
|
||||||
|
run: |
|
||||||
|
./tools/github_workflows/prepare_for_docker_build_and_push.sh ${{ secrets.DOCKERHUB_USERNAME }} ${{ secrets.DOCKERHUB_TOKEN }} asterinas
|
||||||
|
|
||||||
- name: Build and push the Asterinas development image
|
- name: Build and push the Asterinas development image
|
||||||
if: env.asterinas_image_exists == 'false'
|
if: ${{ steps.prepare-for-docker-build-and-push.outputs.is_existed == 'false' }}
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./tools/docker/Dockerfile
|
file: ./tools/docker/Dockerfile
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
load: true
|
tags: asterinas/asterinas:${{ steps.prepare-for-docker-build-and-push.outputs.image_version }}
|
||||||
tags: asterinas/asterinas:${{ steps.fetch-versions.outputs.aster_version }}
|
|
||||||
build-args: |
|
build-args: |
|
||||||
BASE_VERSION=${{ steps.fetch-versions.outputs.aster_version }}
|
BASE_VERSION=${{ steps.prepare-for-docker-build-and-push.outputs.image_version }}
|
||||||
|
|
||||||
|
publish_asterinas_tdx_image:
|
||||||
|
needs: publish_asterinas_image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Prepare for Docker build and push
|
||||||
|
id: prepare-for-docker-build-and-push
|
||||||
|
run: |
|
||||||
|
./tools/github_workflows/prepare_for_docker_build_and_push.sh ${{ secrets.DOCKERHUB_USERNAME }} ${{ secrets.DOCKERHUB_TOKEN }} asterinas-tdx
|
||||||
|
|
||||||
- name: Build and push the Asterinas development image for Intel TDX
|
- name: Build and push the Asterinas development image for Intel TDX
|
||||||
if: env.asterinas_tdx_image_exists == 'false'
|
if: ${{ steps.prepare-for-docker-build-and-push.outputs.is_existed == 'false' }}
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./tools/docker/tdx/Dockerfile
|
file: ./tools/docker/tdx/Dockerfile
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: asterinas/asterinas:${{ steps.fetch-versions.outputs.aster_version }}-tdx
|
tags: asterinas/asterinas:${{ steps.prepare-for-docker-build-and-push.outputs.image_version }}-tdx
|
||||||
build-args: |
|
build-args: |
|
||||||
BASE_VERSION=${{ steps.fetch-versions.outputs.aster_version }}
|
BASE_VERSION=${{ steps.prepare-for-docker-build-and-push.outputs.image_version }}
|
||||||
|
57
tools/github_workflows/prepare_for_docker_build_and_push.sh
Executable file
57
tools/github_workflows/prepare_for_docker_build_and_push.sh
Executable file
@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
|
||||||
|
echo "Prepare the environment for the Github action of docker/build-push-action"
|
||||||
|
echo "Usage: $0 <username> <token> <image_name>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
USERNAME="$1"
|
||||||
|
TOKEN="$2"
|
||||||
|
IMAGE_NAME="$3"
|
||||||
|
|
||||||
|
# Step 1: Set up Docker Buildx
|
||||||
|
echo "Setting up Docker Buildx..."
|
||||||
|
docker buildx create --use || {
|
||||||
|
echo "Failed to set up Docker Buildx"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 2: Login to Docker Hub
|
||||||
|
echo "Logging in to Docker Hub..."
|
||||||
|
echo "${TOKEN}" | docker login -u "${USERNAME}" --password-stdin || {
|
||||||
|
echo "Docker login failed"
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 3: Fetch versions
|
||||||
|
echo "Fetching Docker image version and Rust version..."
|
||||||
|
ASTER_SRC_DIR=$(dirname "$0")/../..
|
||||||
|
IMAGE_VERSION=$(cat ${ASTER_SRC_DIR}/DOCKER_IMAGE_VERSION)
|
||||||
|
RUST_VERSION=$(grep -m1 -o 'nightly-[0-9]\+-[0-9]\+-[0-9]\+' ${ASTER_SRC_DIR}/rust-toolchain.toml)
|
||||||
|
echo "image_version=$IMAGE_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "rust_version=$RUST_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# Step 4: Check if Docker image exists
|
||||||
|
echo "Checking if Docker image exists..."
|
||||||
|
if [[ "${IMAGE_NAME}" == "osdk" ]]; then
|
||||||
|
DOCKER_IMAGE="asterinas/osdk:${IMAGE_VERSION}"
|
||||||
|
elif [[ "${IMAGE_NAME}" == "osdk-tdx" ]]; then
|
||||||
|
DOCKER_IMAGE="asterinas/osdk:${IMAGE_VERSION}-tdx"
|
||||||
|
elif [[ "${IMAGE_NAME}" == "asterinas" ]]; then
|
||||||
|
DOCKER_IMAGE="asterinas/asterinas:${IMAGE_VERSION}"
|
||||||
|
elif [[ "${IMAGE_NAME}" == "asterinas-tdx" ]]; then
|
||||||
|
DOCKER_IMAGE="asterinas/asterinas:${IMAGE_VERSION}-tdx"
|
||||||
|
else
|
||||||
|
echo "Error: Unknown image name '${IMAGE_NAME}'"
|
||||||
|
exit 4
|
||||||
|
fi
|
||||||
|
if docker manifest inspect "${DOCKER_IMAGE}" > /dev/null 2>&1; then
|
||||||
|
echo "is_existed=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "is_existed=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
Reference in New Issue
Block a user