fix buildx helper script
This commit is contained in:
parent
bf7a6e4c09
commit
015737b1e4
2 changed files with 21 additions and 19 deletions
12
Dockerfile
12
Dockerfile
|
@ -12,11 +12,11 @@
|
||||||
# docker buildx create --use
|
# docker buildx create --use
|
||||||
# docker buildx build . --platform=linux/amd64,linux/arm64,linux/arm/v7 --push -t archivebox/archivebox:latest -t archivebox/archivebox:dev
|
# docker buildx build . --platform=linux/amd64,linux/arm64,linux/arm/v7 --push -t archivebox/archivebox:latest -t archivebox/archivebox:dev
|
||||||
#
|
#
|
||||||
# Read more about [developing
|
# Read more about [developing Archivebox](https://github.com/ArchiveBox/ArchiveBox#archivebox-development).
|
||||||
# Archivebox](https://github.com/ArchiveBox/ArchiveBox#archivebox-development).
|
|
||||||
|
|
||||||
|
|
||||||
FROM debian:bookworm-backports
|
FROM debian:bookworm-backports
|
||||||
|
# Debian 12 w/ faster package updates: https://packages.debian.org/bookworm-backports/
|
||||||
|
|
||||||
LABEL name="archivebox" \
|
LABEL name="archivebox" \
|
||||||
maintainer="Nick Sweeting <dockerfile@archivebox.io>" \
|
maintainer="Nick Sweeting <dockerfile@archivebox.io>" \
|
||||||
|
@ -49,19 +49,19 @@ ENV PATH="$PATH:$GLOBAL_VENV/bin:$APP_VENV/bin:$NODE_MODULES/.bin"
|
||||||
|
|
||||||
|
|
||||||
# Create non-privileged user for archivebox and chrome
|
# Create non-privileged user for archivebox and chrome
|
||||||
RUN echo "[*] Setting up system environment..." \
|
RUN echo "[*] Setting up system environment for $ARCHIVEBOX_USER ($TARGETPLATFORM)..." \
|
||||||
&& groupadd --system $ARCHIVEBOX_USER \
|
&& groupadd --system $ARCHIVEBOX_USER \
|
||||||
&& useradd --system --create-home --gid $ARCHIVEBOX_USER --groups audio,video $ARCHIVEBOX_USER \
|
&& useradd --system --create-home --gid $ARCHIVEBOX_USER --groups audio,video $ARCHIVEBOX_USER \
|
||||||
&& mkdir -p /etc/apt/keyrings
|
&& mkdir -p /etc/apt/keyrings
|
||||||
|
|
||||||
# Install system apt dependencies (adding backports to access more recent apt updates)
|
# Install system apt dependencies (adding backports to access more recent apt updates)
|
||||||
RUN echo "[+] Installing system dependencies..." \
|
RUN echo "[+] Installing system dependencies..." \
|
||||||
&& echo 'deb https://deb.debian.org/debian bullseye-backports main contrib non-free' >> /etc/apt/sources.list.d/backports.list \
|
&& echo 'deb https://deb.debian.org/debian bookworm-backports main contrib non-free' >> /etc/apt/sources.list.d/backports.list \
|
||||||
&& apt-get update -qq \
|
&& apt-get update -qq \
|
||||||
&& apt-get install -qq -y \
|
&& apt-get install -qq -y \
|
||||||
apt-transport-https ca-certificates gnupg2 curl wget \
|
apt-transport-https ca-certificates gnupg2 curl wget \
|
||||||
zlib1g-dev dumb-init gosu cron unzip \
|
zlib1g-dev dumb-init gosu cron unzip \
|
||||||
nano iputils-ping dnsutils htop procps \
|
# nano iputils-ping dnsutils htop procps \
|
||||||
# 1. packaging dependencies
|
# 1. packaging dependencies
|
||||||
# 2. docker and init system dependencies
|
# 2. docker and init system dependencies
|
||||||
# 3. frivolous CLI helpers to make debugging failed archiving easier
|
# 3. frivolous CLI helpers to make debugging failed archiving easier
|
||||||
|
@ -108,7 +108,7 @@ RUN echo "[+] Installing extractor APT dependencies..." \
|
||||||
ENV PLAYWRIGHT_BROWSERS_PATH="/browsers"
|
ENV PLAYWRIGHT_BROWSERS_PATH="/browsers"
|
||||||
RUN echo "[+] Installing extractor Chromium dependency..." \
|
RUN echo "[+] Installing extractor Chromium dependency..." \
|
||||||
&& apt-get update -qq \
|
&& apt-get update -qq \
|
||||||
&& $GLOBAL_VENV/bin/pip install playwright \
|
&& ($GLOBAL_VENV/bin/pip install playwright || [[ "$TARGETPLATFORM" == "linux/arm/v7" ]]) \
|
||||||
&& $GLOBAL_VENV/bin/playwright install --with-deps chromium \
|
&& $GLOBAL_VENV/bin/playwright install --with-deps chromium \
|
||||||
&& CHROME_BINARY="$($GLOBAL_VENV/bin/python -c 'from playwright.sync_api import sync_playwright; print(sync_playwright().start().chromium.executable_path)')" \
|
&& CHROME_BINARY="$($GLOBAL_VENV/bin/python -c 'from playwright.sync_api import sync_playwright; print(sync_playwright().start().chromium.executable_path)')" \
|
||||||
&& ln -s "$CHROME_BINARY" /usr/bin/chromium-browser \
|
&& ln -s "$CHROME_BINARY" /usr/bin/chromium-browser \
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# ./bin/build_docker.sh dev 'linux/arm/v7'
|
||||||
|
|
||||||
### Bash Environment Setup
|
### Bash Environment Setup
|
||||||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
||||||
|
@ -15,10 +16,12 @@ cd "$REPO_DIR"
|
||||||
which docker > /dev/null || exit 1
|
which docker > /dev/null || exit 1
|
||||||
|
|
||||||
|
|
||||||
TAG_NAME="dev"
|
TAG_NAME="${1:-$(git rev-parse --abbrev-ref HEAD)}"
|
||||||
VERSION="$(jq -r '.version' < "$REPO_DIR/package.json")"
|
VERSION="$(jq -r '.version' < "$REPO_DIR/package.json")"
|
||||||
SHORT_VERSION="$(echo "$VERSION" | perl -pe 's/(\d+)\.(\d+)\.(\d+)/$1.$2/g')"
|
SHORT_VERSION="$(echo "$VERSION" | perl -pe 's/(\d+)\.(\d+)\.(\d+)/$1.$2/g')"
|
||||||
REQUIRED_PLATFORMS=('linux/arm64','linux/amd64','linux/arm/v8','linux/arm/v7')
|
REQUIRED_PLATFORMS="${2:-"linux/arm64,linux/amd64,linux/arm/v7"}"
|
||||||
|
|
||||||
|
echo "[+] Building Docker image: tag=$TAG_NAME version=$SHORT_VERSION arch=$REQUIRED_PLATFORMS"
|
||||||
|
|
||||||
function check_platforms() {
|
function check_platforms() {
|
||||||
INSTALLED_PLATFORMS="$(docker buildx inspect | grep 'Platforms:' )"
|
INSTALLED_PLATFORMS="$(docker buildx inspect | grep 'Platforms:' )"
|
||||||
|
@ -33,34 +36,32 @@ function check_platforms() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function remove_builder() {
|
||||||
|
# remove existing xbuilder
|
||||||
|
docker buildx stop xbuilder || true
|
||||||
|
docker buildx rm xbuilder || true
|
||||||
|
}
|
||||||
|
|
||||||
function create_builder() {
|
function create_builder() {
|
||||||
|
docker buildx use xbuilder && return 0
|
||||||
echo "[+] Creating new xbuilder for: $REQUIRED_PLATFORMS"
|
echo "[+] Creating new xbuilder for: $REQUIRED_PLATFORMS"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Switch to buildx builder if already present / previously created
|
# Switch to buildx builder if already present / previously created
|
||||||
docker buildx create --name xbuilder --driver docker-container --bootstrap --use --platform "$REQUIRED_PLATFORMS" || true
|
docker buildx create --name xbuilder --driver docker-container --bootstrap --use --platform "$REQUIRED_PLATFORMS" || true
|
||||||
docker buildx inspect --bootstrap || true
|
docker buildx inspect --bootstrap || true
|
||||||
|
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function recreate_builder() {
|
function recreate_builder() {
|
||||||
# Install QEMU binaries for cross-platform building if not installed
|
# Install QEMU binaries for cross-platform building if not installed
|
||||||
docker run --privileged --rm 'tonistiigi/binfmt' --install all
|
docker run --privileged --rm 'tonistiigi/binfmt' --install all
|
||||||
|
|
||||||
# remove existing xbuilder
|
remove_builder
|
||||||
docker buildx stop xbuilder || true
|
|
||||||
docker buildx rm xbuilder || true
|
|
||||||
|
|
||||||
# Create Docker builder for cross-platform building
|
|
||||||
docker buildx use xbuilder && return 0
|
|
||||||
|
|
||||||
create_builder
|
create_builder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Check if docker is ready for cross-plaform builds, if not, recreate builder
|
# Check if docker is ready for cross-plaform builds, if not, recreate builder
|
||||||
docker buildx use xbuilder || create_builder
|
docker buildx use xbuilder 2>&1 >/dev/null || create_builder
|
||||||
check_platforms || (recreate_builder && check_platforms) || exit 1
|
check_platforms || (recreate_builder && check_platforms) || exit 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,6 +73,7 @@ docker buildx build --platform "$REQUIRED_PLATFORMS" --load . \
|
||||||
-t archivebox:$TAG_NAME \
|
-t archivebox:$TAG_NAME \
|
||||||
-t archivebox:$VERSION \
|
-t archivebox:$VERSION \
|
||||||
-t archivebox:$SHORT_VERSION \
|
-t archivebox:$SHORT_VERSION \
|
||||||
|
-t archivebox:latest \
|
||||||
-t docker.io/nikisweeting/archivebox:$TAG_NAME \
|
-t docker.io/nikisweeting/archivebox:$TAG_NAME \
|
||||||
-t docker.io/nikisweeting/archivebox:$VERSION \
|
-t docker.io/nikisweeting/archivebox:$VERSION \
|
||||||
-t docker.io/nikisweeting/archivebox:$SHORT_VERSION \
|
-t docker.io/nikisweeting/archivebox:$SHORT_VERSION \
|
||||||
|
|
Loading…
Reference in a new issue