Skip to content

Commit

Permalink
debian docker images using statically-linked binary (musl)
Browse files Browse the repository at this point in the history
debian 12.0 image variants:
- docker pull joseluisq/static-web-server:2-debian
- docker pull joseluisq/static-web-server:2.y-debian
- docker pull joseluisq/static-web-server:2.y.z-debian
  • Loading branch information
joseluisq committed Jun 13, 2023
1 parent 558fd96 commit 3adf75e
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 9 deletions.
120 changes: 117 additions & 3 deletions .github/workflows/devel.docker.yml
Expand Up @@ -14,7 +14,7 @@ env:

jobs:
docker-alpine:
name: Docker test
name: Docker test (alpine)
strategy:
matrix:
arch:
Expand Down Expand Up @@ -44,9 +44,9 @@ jobs:
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: static-web-server-${{ matrix.arch }}-buildx-${{ github.sha }}
key: static-web-server-${{ matrix.arch }}-alpine-buildx-${{ github.sha }}
restore-keys: |
static-web-server-${{ matrix.arch }}-buildx-
static-web-server-${{ matrix.arch }}-alpine-buildx-
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down Expand Up @@ -125,3 +125,117 @@ jobs:
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
docker-debian:
name: Docker test (debian)
strategy:
matrix:
arch:
- linux/amd64
- linux/386
- linux/arm64
- linux/arm/v7
- linux/arm/v6
runs-on: ubuntu-22.04
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Dependencies
run: |
sudo apt-get install jq
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
-
name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: static-web-server-${{ matrix.arch }}-debian-buildx-${{ github.sha }}
restore-keys: |
static-web-server-${{ matrix.arch }}-debian-buildx-
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Docker meta debian
id: meta_debian
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_IMAGE }}
flavor: |
latest=false
suffix=-debian
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
-
name: Prepare Docker envs
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
scripts/ci/get_latest_release.sh
cat /tmp/version >> $GITHUB_ENV
cat /tmp/version
echo "SERVER_DOCKERFILE=./docker/debian/Dockerfile" >> $GITHUB_ENV
-
name: Build and export to Docker client
uses: docker/build-push-action@v4
with:
context: .
platforms: ${{ matrix.arch }}
file: ${{ env.SERVER_DOCKERFILE }}
load: true
tags: ${{ steps.meta_debian.outputs.tags }}
labels: ${{ steps.meta_debian.outputs.labels }}
build-args: |
SERVER_VERSION=${{ env.SERVER_VERSION }}
-
name: Build and push to local registry
uses: docker/build-push-action@v4
with:
context: .
platforms: ${{ matrix.arch }}
file: ${{ env.SERVER_DOCKERFILE }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta_debian.outputs.tags }}
labels: ${{ steps.meta_debian.outputs.labels }}
build-args: |
SERVER_VERSION=${{ env.SERVER_VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
-
name: Inspect image
run: |
docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta_debian.outputs.version }}
-
name: Check manifest
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta_debian.outputs.version }}
-
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
53 changes: 53 additions & 0 deletions .github/workflows/release.docker.yml
Expand Up @@ -57,6 +57,59 @@ jobs:
build-args: |
SERVER_VERSION=${{ env.SERVER_VERSION }}
docker-image-debian:
needs: ['docker-image-alpine']
runs-on: ubuntu-22.04
if: contains(github.ref, 'v2.')
steps:
-
name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Docker meta debian
id: meta_debian
uses: docker/metadata-action@v4
with:
images: joseluisq/static-web-server
flavor: |
latest=false
suffix=-debian
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Prepare Docker envs
shell: bash
run: |
echo "SERVER_VERSION=${GITHUB_REF##*/v}" >> $GITHUB_ENV
echo "SERVER_DOCKERFILE=./docker/debian/Dockerfile" >> $GITHUB_ENV
-
name: Build and push (debian)
uses: docker/build-push-action@v4
with:
push: true
context: .
platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6
file: ${{ env.SERVER_DOCKERFILE }}
tags: ${{ steps.meta_debian.outputs.tags }}
build-args: |
SERVER_VERSION=${{ env.SERVER_VERSION }}
docker-image-scratch:
needs: ['docker-image-alpine']
runs-on: ubuntu-22.04
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -26,6 +26,7 @@ docs/site
docs/*/**.html
*/**/*.1
docs/docs
docker/devel/static-web-server

!/docs
!/tests/fixtures/**/*
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Expand Up @@ -125,6 +125,15 @@ docker.image.alpine:
-t joseluisq/${PKG_NAME}:devel-alpine . --pull=true
.PHONY: docker.image.alpine

docker.image.debian:
@echo "Creating Docker Alpine image..."
@cp -frp ./target/x86_64-unknown-linux-gnu/release/static-web-server ./docker/devel/
@docker build \
--platform="linux/x86_64" \
--rm=true -f ./docker/devel/Dockerfile.debian \
-t joseluisq/${PKG_NAME}:devel-debian . --pull=true
.PHONY: docker.image.debian


#######################################
########## Production tasks ###########
Expand Down
80 changes: 80 additions & 0 deletions docker/debian/Dockerfile
@@ -0,0 +1,80 @@
FROM --platform=$BUILDPLATFORM debian:12.0-slim as build

ARG TARGETPLATFORM
ARG SERVER_VERSION=0.0.0
ENV SERVER_VERSION=${SERVER_VERSION}

RUN set -eux \
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
ca-certificates \
curl \
file \
tzdata \
&& true

RUN set -ex \
&& case "$TARGETPLATFORM" in \
"linux/amd64") target='x86_64-unknown-linux-musl' ;; \
"linux/arm64") target='aarch64-unknown-linux-musl' ;; \
"linux/386") target='i686-unknown-linux-musl' ;; \
"linux/arm/v7") target='armv7-unknown-linux-musleabihf' ;; \
"linux/arm/v6") target='arm-unknown-linux-musleabihf' ;; \
*) echo >&2 "error: unsupported $TARGETPLATFORM architecture"; exit 1 ;; \
esac \
&& curl -Lo /tmp/static-web-server.tar.gz \
"https://github.com/static-web-server/static-web-server/releases/download/v${SERVER_VERSION}/static-web-server-v${SERVER_VERSION}-${target}.tar.gz" \
&& tar xzvf /tmp/static-web-server.tar.gz \
&& cp static-web-server-v${SERVER_VERSION}-${target}/static-web-server /usr/local/bin/ \
&& rm -rf /tmp/static-web-server.tar.gz static-web-server-v${SERVER_VERSION}-${target} \
&& chmod +x /usr/local/bin/static-web-server \
&& true

RUN set -ex \
&& echo "Testing Docker image..." \
&& uname -a \
&& cat /etc/os-release \
&& echo VERSION_NUMBER=$(cat /etc/debian_version) \
&& static-web-server --version \
&& static-web-server --help \
&& file /usr/local/bin/static-web-server \
&& true

FROM debian:12.0-slim

ARG SERVER_VERSION=0.0.0
ENV SERVER_VERSION=${SERVER_VERSION}

LABEL version="${SERVER_VERSION}" \
description="A cross-platform, high-performance and asynchronous web server for static files-serving." \
maintainer="Jose Quintana <joseluisq.net>"

RUN set -eux \
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
ca-certificates \
tzdata \
# Clean up local repository of retrieved packages and remove the package lists
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& true

COPY --from=build /usr/local/bin/static-web-server /usr/local/bin/
COPY ./docker/debian/entrypoint.sh /
COPY ./docker/public /public

EXPOSE 80

STOPSIGNAL SIGQUIT

ENTRYPOINT ["/entrypoint.sh"]

CMD ["static-web-server"]

# Metadata
LABEL org.opencontainers.image.vendor="Jose Quintana" \
org.opencontainers.image.url="https://github.com/static-web-server/static-web-server" \
org.opencontainers.image.title="Static Web Server" \
org.opencontainers.image.description="A cross-platform, high-performance and asynchronous web server for static files-serving." \
org.opencontainers.image.version="${SERVER_VERSION}" \
org.opencontainers.image.documentation="https://static-web-server.net"
10 changes: 10 additions & 0 deletions docker/debian/entrypoint.sh
@@ -0,0 +1,10 @@
#!/bin/sh

set -e

# Check if incoming command contains flags.
if [ "${1#-}" != "$1" ]; then
set -- static-web-server "$@"
fi

exec "$@"
37 changes: 37 additions & 0 deletions docker/devel/Dockerfile.debian
@@ -0,0 +1,37 @@
FROM debian:12.0-slim

ENV SERVER_VERSION=devel

LABEL version="${SERVER_VERSION}" \
description="A cross-platform, high-performance and asynchronous web server for static files-serving." \
maintainer="Jose Quintana <joseluisq.net>"

RUN set -eux \
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
ca-certificates \
tzdata \
# Clean up local repository of retrieved packages and remove the package lists
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& true

COPY ./docker/devel/static-web-server /usr/local/bin/
COPY ./docker/debian/entrypoint.sh /
COPY ./docker/public /public

EXPOSE 80

STOPSIGNAL SIGQUIT

ENTRYPOINT ["/entrypoint.sh"]

CMD ["static-web-server"]

# Metadata
LABEL org.opencontainers.image.vendor="Jose Quintana" \
org.opencontainers.image.url="https://github.com/static-web-server/static-web-server" \
org.opencontainers.image.title="Static Web Server" \
org.opencontainers.image.description="A cross-platform, high-performance and asynchronous web server for static files-serving." \
org.opencontainers.image.version="${SERVER_VERSION}" \
org.opencontainers.image.documentation="https://github.com/static-web-server/static-web-server"

0 comments on commit 3adf75e

Please sign in to comment.