From 7ebc40b082f97e473846d0a51427dc563c26f04a Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Wed, 13 Mar 2024 20:24:52 +0800 Subject: [PATCH] chore: try to pull first then build --- .github/workflows/container.yml | 2 +- build_image.sh | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 9d82b10..60a8cde 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -17,7 +17,7 @@ jobs: path: | ~/.local/share/containers ~/.config/containers - key: ${{ runner.os }}-${{ hashFiles('**/*.Dockerfile', 'build_image.sh', 'VERSION', 'go.*') }} + key: ${{ runner.os }} - name: Login to Container Registry uses: redhat-actions/podman-login@v1 with: diff --git a/build_image.sh b/build_image.sh index 6bb08c4..5146583 100755 --- a/build_image.sh +++ b/build_image.sh @@ -9,6 +9,12 @@ log_info "VERSION: $VERSION" # Image Prefix IMAGE_PREFIX=${IMAGE_PREFIX:-"git.0x7f.app/woj"} +function docker_pull() { + tag_name="$IMAGE_PREFIX/$1:$VERSION" + shift 1 + $DOCKER pull "$tag_name" "$@" || log_warn "[!] Failed to pull $tag_name" +} + function docker_build() { tag_name="$IMAGE_PREFIX/$1:$VERSION" docker_file="$2" @@ -26,6 +32,8 @@ function docker_push() { function build_rootfs() { log_info "[+] Building Rootfs Images" pushd resource/runner || exit 1 + docker_pull "debian-full" + docker_pull "debian-run" docker_build "debian-full" "scripts/debian-full.Dockerfile" docker_build "debian-run" "scripts/debian-run.Dockerfile" popd || exit 1 @@ -39,16 +47,19 @@ function push_rootfs() { function build_base() { log_info "[+] Building Base" + docker_pull "woj-server-base" docker_build "woj-server-base" "Base.Dockerfile" } function build_server() { log_info "[+] Building Server" + docker_pull "woj-server" docker_build "woj-server" "Server.Dockerfile" } function build_runner() { log_info "[+] Building Runner" + docker_pull "woj-runner" docker_build "woj-runner" "Runner.Dockerfile" } @@ -61,14 +72,14 @@ function push_base() { function push_server() { log_info "[+] Pushing Server Images" - docker_push "woj-server" + docker_push "woj-server:$VERSION" $DOCKER tag "$IMAGE_PREFIX/woj-server:$VERSION" "$IMAGE_PREFIX/woj-server:latest" docker_push "woj-server:latest" } function push_runner() { log_info "[+] Pushing Runner Images" - docker_push "woj-runner" + docker_push "woj-runner:$VERSION" $DOCKER tag "$IMAGE_PREFIX/woj-runner:$VERSION" "$IMAGE_PREFIX/woj-runner:latest" docker_push "woj-runner:latest" }