-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Dockerfile to build a Docker image (#652)
Co-authored-by: Vinh Nguyen <[email protected]>
- Loading branch information
1 parent
1ed0d7e
commit e439935
Showing
8 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Package the Node.js project into a single binary | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16.16.0-alpine3.16 as builder | ||
|
||
# Workaround: https://github.com/nodejs/docker-node/issues/813#issuecomment-407339011 | ||
# Error: could not get uid/gid | ||
# [ 'nobody', 0 ] | ||
RUN npm config set unsafe-perm true | ||
|
||
RUN npm install --location=global [email protected] [email protected] | ||
|
||
ENV NODE node16 | ||
ENV PLATFORM alpine | ||
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM} -a $([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") | ||
|
||
COPY package.json package-lock.json /app/ | ||
COPY lib /app/lib | ||
COPY bin /app/bin | ||
COPY css /app/css | ||
WORKDIR /app | ||
|
||
RUN PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 npm ci | ||
|
||
RUN /usr/local/bin/pkg bin/asciidoctor-web-pdf --config package.json --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") -o app.bin | ||
|
||
# Create the image | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.1 | ||
|
||
RUN addgroup -g 1000 asciidoctor && adduser -D -G asciidoctor -u 1000 asciidoctor | ||
|
||
RUN apk add --quiet --no-cache --update chromium font-noto-emoji ttf-freefont font-noto \ | ||
&& fc-cache -f | ||
|
||
COPY --chown=asciidoctor:asciidoctor --from=builder /app/app.bin /usr/bin/asciidoctor-web-pdf | ||
COPY --chown=asciidoctor:asciidoctor --from=builder /app/node_modules/mathjax/es5 /usr/bin/assets/mathjax | ||
|
||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/lib/chromium/chrome | ||
|
||
RUN mkdir /usr/app && chown asciidoctor:asciidoctor /usr/app | ||
|
||
USER asciidoctor | ||
WORKDIR /usr/app | ||
|
||
ENTRYPOINT ["/usr/bin/asciidoctor-web-pdf"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
MULTI_ARCH_AVAILABLE := $(shell docker buildx inspect | grep amd64 | grep arm64 > /dev/null 2>&1; echo $$?) | ||
|
||
.PHONY: packageDocker publishDocker | ||
|
||
default: packageDocker | ||
|
||
packageDocker: | ||
ifeq ($(MULTI_ARCH_AVAILABLE), 0) | ||
docker buildx build --tag asciidoctor-web-pdf:latest -o type="image,push=false" --platform linux/amd64,linux/arm64 . | ||
else | ||
docker build -t asciidoctor-web-pdf . | ||
endif | ||
|
||
packageLocalDocker: | ||
docker build -t asciidoctor-web-pdf:latest . | ||
|
||
testDocker: | ||
echo "= Test" | docker run -i --rm asciidoctor-web-pdf:latest -a reproducible - > test/output/docker-smoke-test.pdf | ||
md5sum -c test/docker-smoke-test.md5sum | ||
|
||
publishDocker: | ||
ifndef RELEASE_VERSION | ||
$(error RELEASE_VERSION is undefined) | ||
endif | ||
docker buildx build --push --platform linux/amd64,linux/arm64 --tag asciidoctor-web-pdf:latest --tag asciidoctor-web-pdf:${RELEASE_VERSION} . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
67b7ee0303907fdd271dd80df8aab3a8 test/output/docker-smoke-test.pdf |
Empty file.