Skip to content

Commit

Permalink
Bundle all requirements in one image
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Aug 3, 2021
1 parent 729e6d2 commit 8a75a4c
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,90 @@ jobs:
path: ./dist/*
if-no-files-found: error

allinone:
if: github.repository == 'wabarc/wayback'
name: AllInOne Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout default branch
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Prepare
id: prep
run: |
GHCR_HOST=ghcr.io
DOCKER_IMAGE_SCOPE=${{ github.repository }} # foo/bar
if [ "${{ github.event_name }}" = "schedule" ]; then
DOCKER_IMAGE_VERSION=nightly-bundle
elif [[ $GITHUB_REF == refs/tags/* ]]; then
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/v}-bundle
TAGS="${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}"
else
DOCKER_IMAGE_VERSION=edge-bundle
fi
TAGS="${TAGS},${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}:${DOCKER_IMAGE_VERSION}"
echo ::set-output name=tags::${TAGS}
echo ::set-output name=version::${DOCKER_IMAGE_VERSION}
echo ::set-output name=ghcr::${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}
echo ::set-output name=images::${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate meta
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ steps.prep.outputs.images }}
tags: |
type=semver,pattern=${{ steps.prep.outputs.version }}
type=raw,${{ steps.prep.outputs.version }}
- name: Build artifacts
uses: docker/bake-action@v1
with:
files: ./docker-bake.hcl
targets: artifact-all
set: |
*.cache-from=type=local,src=/tmp/.image-cache/artifacts
*.cache-to=type=local,dest=/tmp/.image-cache-new/artifacts
- name: Build and push Docker image
uses: docker/bake-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: bundle
push: ${{ github.event_name != 'pull_request' }}
set: |
*.cache-from=type=local,src=/tmp/.image-cache/image
*.cache-to=type=local,dest=/tmp/.image-cache-new/image
- name: Check manifest
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
- name: Inspect image
if: github.event_name != 'pull_request'
run: |
docker pull ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
docker image inspect ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
dispatch:
if: github.repository == 'wabarc/wayback'
name: Repository Dispatch
Expand Down
89 changes: 89 additions & 0 deletions build/docker/Dockerfile.all
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# syntax=docker/dockerfile:1.2
ARG GO_VERSION=1.16

FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS builder
COPY --from=tonistiigi/xx:golang / /

RUN apk add --no-cache -U build-base ca-certificates linux-headers musl-dev git tar

ARG TARGETPLATFORM
WORKDIR /src

COPY . .
RUN --mount=type=bind,target=/src,rw \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
sh ./build/binary.sh $TARGETPLATFORM \
&& mv ./build/binary/wayback-* /wayback

# Application layer
FROM alpine:3.13

LABEL org.wabarc.homepage="http://github.com/wabarc" \
org.wabarc.repository="http://github.com/wabarc/wayback"

ARG TOR_EXCLUDE_NODE="{cn},{hk},{mo},{sg},{th},{pk},{by},{ru},{ir},{sy},{vn},{ph},{my},{cu}"
ARG TOR_EXCLUDE_EXIT_NODE="{cn},{hk},{mo},{sg},{kp},{th},{pk},{by},{ru},{ir},{sy},{vn},{ph},{my},{cu},{au},{ca},{nz},{gb},{us},{fr},{dk},{nl},{no},{be},{de},{it},{es}"

ENV BASE_DIR /wayback
ENV PUSER wayback
ENV PGROUP wayback
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANGUAGE en_US.UTF-8

WORKDIR $BASE_DIR

RUN set -o pipefail; \
addgroup --system "${PGROUP}"; \
adduser --system --no-create-home --disabled-password \
--gecos '' --home "${BASE_DIR}" --ingroup "${PGROUP}" "${PUSER}"; \
chown -R "${PUSER}:${PGROUP}" "${BASE_DIR}"; \
chmod -R g+w "${BASE_DIR}"

COPY --from=builder /wayback /usr/local/bin
RUN set -o pipefail; \
apk add --no-cache -U ca-certificates libressl wget tor; \
rm -rf /var/cache/apk/*; \
\
mv /etc/tor/torrc.sample /etc/tor/torrc; \
#echo "ExcludeNodes ${TOR_EXCLUDE_NODE}" >> /etc/tor/torrc; \
#echo "ExcludeExitNodes ${TOR_EXCLUDE_EXIT_NODE}" >> /etc/tor/torrc; \
#echo 'StrictNodes 1' >> /etc/tor/torrc; \
echo 'SocksPort 0' >> /etc/tor/torrc; \
echo 'ExitRelay 0' >> /etc/tor/torrc; \
echo 'LongLivedPorts 8964' >> /etc/tor/torrc; \
#echo 'User tor' >> /etc/tor/torrc; \
chmod a+w /var/log/tor

# Ref: https://wiki.alpinelinux.org/wiki/Fonts
RUN set -o pipefail; \
apk add --no-cache -U \
chromium \
dbus \
dumb-init \
ffmpeg \
freetype \
libstdc++ \
harfbuzz \
nss \
you-get \
rtmpdump \
youtube-dl \
libwebp-tools \
ttf-freefont \
ttf-font-awesome \
font-noto \
font-noto-arabic \
font-noto-emoji \
font-noto-cjk \
font-noto-extra \
font-noto-lao \
font-noto-myanmar \
font-noto-thai \
font-noto-tibetan; \
rm -rf /var/cache/apk/* /tmp/* /var/tmp/*

EXPOSE 8964

CMD ["/usr/local/bin/wayback"]
File renamed without changes.
15 changes: 15 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ target "release" {
"linux/s390x"
]
}

target "bundle" {
inherits = ["docker-metadata-action"]
context = "./"
dockerfile = "./build/docker/Dockerfile.all"
platforms = [
"linux/386",
"linux/amd64",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm64",
"linux/ppc64le",
"linux/s390x"
]
}

0 comments on commit 8a75a4c

Please sign in to comment.