From 1cc986a4de5fa99a260a7d27d4ac458e52eb42ff Mon Sep 17 00:00:00 2001 From: MU-Software Date: Sun, 21 Jan 2024 21:41:08 +0900 Subject: [PATCH] I hate you dockerhub --- infra/Dockerfile | 11 +++++------ infra/hooks/build | 10 ++++++++++ infra/hooks/pre_build | 13 +++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 infra/hooks/build create mode 100644 infra/hooks/pre_build diff --git a/infra/Dockerfile b/infra/Dockerfile index 8c98357..22be4a1 100644 --- a/infra/Dockerfile +++ b/infra/Dockerfile @@ -2,9 +2,9 @@ FROM --platform=linux/arm64 python:3.11-slim-bookworm as base # ============================================================================== FROM base as builder +SHELL ["bash", "-euxvc"] -RUN set -eux; \ - apt-get update; \ +RUN apt-get update; \ apt-get install -y --no-install-recommends curl openssh-client gcc git libpq-dev; \ curl -sSL https://install.python-poetry.org | python3.11 -; @@ -12,13 +12,13 @@ ENV PATH="${PATH}:/root/.local/bin:" COPY ../poetry.lock ../pyproject.toml ./ -RUN set -eux; \ - poetry config experimental.system-git-client true; \ +RUN poetry config experimental.system-git-client true; \ poetry config virtualenvs.create false; \ poetry install --only main --no-interaction --no-ansi --no-root; # ============================================================================== FROM base as runtime +SHELL ["bash", "-euxvc"] ARG GIT_HASH ENV TZ=Asia/Seoul \ @@ -27,8 +27,7 @@ ENV TZ=Asia/Seoul \ PYTHONIOENCODING=UTF-8 \ DEPLOYMENT_GIT_HASH=$GIT_HASH -RUN set -eux; \ - ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone; \ +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone; \ apt-get update; \ apt-get install -y --no-install-recommends curl wget ca-certificates gnupg lsb-release; diff --git a/infra/hooks/build b/infra/hooks/build new file mode 100644 index 0000000..f390d3c --- /dev/null +++ b/infra/hooks/build @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +docker build \ + -t $IMAGE_NAME \ + -f Dockerfile \ + --target runtime \ + --build-arg GIT_HASH="$(git rev-parse HEAD)" \ + --build-arg INVALIDATE_CACHE_DATE="$(date +%Y-%m-%d_%H:%M:%S)" \ + ../ diff --git a/infra/hooks/pre_build b/infra/hooks/pre_build new file mode 100644 index 0000000..b917576 --- /dev/null +++ b/infra/hooks/pre_build @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +HOST_ARCH=$(uname -m) + +if [ x"${HOST_ARCH}" == x"aarch64" ]; then + echo "Building arm64 image natively" + exit +fi + +# Register qemu-*-static for all supported processors except the +# current one, but also remove all registered binfmt_misc before +docker run --rm --privileged multiarch/qemu-user-static:register --reset