chore: try to pull first then build

This commit is contained in:
Paul Pan 2024-03-13 20:24:52 +08:00
parent ff98b7b05f
commit 7ebc40b082
Signed by: Paul
GPG Key ID: D639BDF5BA578AF4
2 changed files with 14 additions and 3 deletions

View File

@ -17,7 +17,7 @@ jobs:
path: | path: |
~/.local/share/containers ~/.local/share/containers
~/.config/containers ~/.config/containers
key: ${{ runner.os }}-${{ hashFiles('**/*.Dockerfile', 'build_image.sh', 'VERSION', 'go.*') }} key: ${{ runner.os }}
- name: Login to Container Registry - name: Login to Container Registry
uses: redhat-actions/podman-login@v1 uses: redhat-actions/podman-login@v1
with: with:

View File

@ -9,6 +9,12 @@ log_info "VERSION: $VERSION"
# Image Prefix # Image Prefix
IMAGE_PREFIX=${IMAGE_PREFIX:-"git.0x7f.app/woj"} 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() { function docker_build() {
tag_name="$IMAGE_PREFIX/$1:$VERSION" tag_name="$IMAGE_PREFIX/$1:$VERSION"
docker_file="$2" docker_file="$2"
@ -26,6 +32,8 @@ function docker_push() {
function build_rootfs() { function build_rootfs() {
log_info "[+] Building Rootfs Images" log_info "[+] Building Rootfs Images"
pushd resource/runner || exit 1 pushd resource/runner || exit 1
docker_pull "debian-full"
docker_pull "debian-run"
docker_build "debian-full" "scripts/debian-full.Dockerfile" docker_build "debian-full" "scripts/debian-full.Dockerfile"
docker_build "debian-run" "scripts/debian-run.Dockerfile" docker_build "debian-run" "scripts/debian-run.Dockerfile"
popd || exit 1 popd || exit 1
@ -39,16 +47,19 @@ function push_rootfs() {
function build_base() { function build_base() {
log_info "[+] Building Base" log_info "[+] Building Base"
docker_pull "woj-server-base"
docker_build "woj-server-base" "Base.Dockerfile" docker_build "woj-server-base" "Base.Dockerfile"
} }
function build_server() { function build_server() {
log_info "[+] Building Server" log_info "[+] Building Server"
docker_pull "woj-server"
docker_build "woj-server" "Server.Dockerfile" docker_build "woj-server" "Server.Dockerfile"
} }
function build_runner() { function build_runner() {
log_info "[+] Building Runner" log_info "[+] Building Runner"
docker_pull "woj-runner"
docker_build "woj-runner" "Runner.Dockerfile" docker_build "woj-runner" "Runner.Dockerfile"
} }
@ -61,14 +72,14 @@ function push_base() {
function push_server() { function push_server() {
log_info "[+] Pushing Server Images" 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 tag "$IMAGE_PREFIX/woj-server:$VERSION" "$IMAGE_PREFIX/woj-server:latest"
docker_push "woj-server:latest" docker_push "woj-server:latest"
} }
function push_runner() { function push_runner() {
log_info "[+] Pushing Runner Images" 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 tag "$IMAGE_PREFIX/woj-runner:$VERSION" "$IMAGE_PREFIX/woj-runner:latest"
docker_push "woj-runner:latest" docker_push "woj-runner:latest"
} }