docker: add Docker image for ARM.

* Have CI build Docker images for both x86 and ARM.
* Add a `bin/rails danbooru:docker:build-arm` command for building a Docker image locally for ARM.

Usage:

* Test the image:

  docker run --rm -it --platform linux/arm64 ghcr.io/danbooru/danbooru bash

* Build the image:

  bin/rails danbooru:docker:build-arm

* Build the image by hand:

  git archive HEAD | docker buildx build - --platform linux/amd64 --build-arg SOURCE_COMMIT=$(git rev-parse HEAD) -t danbooru -f Dockerfile --load
This commit is contained in:
evazion
2022-04-24 18:35:03 -05:00
parent e698bf91ee
commit 2b387bdc41
3 changed files with 25 additions and 5 deletions

View File

@@ -27,6 +27,13 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# https://github.com/docker/setup-qemu-action
# https://github.com/docker/setup-buildx-action#with-qemu
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: arm64
# https://github.com/docker/setup-buildx-action # https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
@@ -73,6 +80,8 @@ jobs:
tags: ${{ steps.metadata.outputs.tags }} tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }} labels: ${{ steps.metadata.outputs.labels }}
platforms: linux/amd64,linux/arm64
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache # https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache
# https://dev.to/pst418/speed-up-multi-stage-docker-builds-in-ci-cd-with-buildkit-s-registry-cache-11gi # https://dev.to/pst418/speed-up-multi-stage-docker-builds-in-ci-cd-with-buildkit-s-registry-cache-11gi
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache

View File

@@ -61,7 +61,7 @@ RUN \
FROM base as production FROM base as production
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 ENV LD_PRELOAD=libjemalloc.so.2
ENV MALLOC_CONF=background_thread:true,narenas:2,dirty_decay_ms:1000,muzzy_decay_ms:0,tcache:false ENV MALLOC_CONF=background_thread:true,narenas:2,dirty_decay_ms:1000,muzzy_decay_ms:0,tcache:false
COPY --from=development /root /root COPY --from=development /root /root

View File

@@ -104,11 +104,22 @@ namespace :danbooru do
namespace :docker do namespace :docker do
# Usage: bin/rails danbooru:docker:build # Usage: bin/rails danbooru:docker:build
# #
# Build a Docker image. Note that uncommited changes won't be included in # Build a Docker image. Note that uncommited changes won't be included in the image; commit changes to Git first before building the image.
# the image; commit changes first before building the image. desc "Build a Docker image"
desc "Build a Docker image based on latest commit"
task :build do task :build do
system("git archive HEAD | docker buildx build - --build-arg SOURCE_COMMIT=$(git rev-parse HEAD) -t danbooru -f Dockerfile") system("git archive HEAD | docker buildx build - --platform linux/amd64 --build-arg SOURCE_COMMIT=$(git rev-parse HEAD) --tag danbooru --tag danbooru:x86 --file Dockerfile --load")
end
# Usage: bin/rails danbooru:docker:build-arm
#
# Build a Docker image for ARM. You may need to install QEMU first if building on x86.
#
# * sudo apt-get install qemu binfmt-support qemu-user-static # Install QEMU
# * docker run --rm -it --platform linux/arm64 ubuntu # Test that QEMU works
# * docker run --rm -it --platform linux/arm64 danbooru:arm -- bash # Test that the Danbooru image works
desc "Build a Docker image for ARM"
task :"build-arm" do
system("git archive HEAD | docker buildx build - --platform linux/arm64 --build-arg SOURCE_COMMIT=$(git rev-parse HEAD) --tag danbooru --tag danbooru:arm --file Dockerfile --load")
end end
end end