Skip to content

Commit

Permalink
feat: own dockerfile (#6)
Browse files Browse the repository at this point in the history
- Build own images for different platforms
- Generalize Dockerfile
- Update yarn, refactor a bit
- update actions
  • Loading branch information
olegstepura authored Nov 9, 2022
1 parent 4f8def0 commit 1c7825d
Show file tree
Hide file tree
Showing 18 changed files with 978 additions and 690 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
env:
TAG: html-to-pdf
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
- run: yarn install
- run: yarn lint --max-warnings 0
- name: Build container
run: docker build --file deploy/test/Dockerfile --tag ${TAG} .
run: docker build --file deploy/Dockerfile --target test --tag ${TAG} .
- name: Run test in a container
run: docker run --rm ${TAG} yarn test
24 changes: 14 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Define docker image metadata
uses: docker/metadata-action@v3
id: metadata
uses: docker/metadata-action@v4
id: meta
with:
images: muehlemannpopp/html-to-pdf
tags: |
Expand All @@ -27,14 +30,15 @@ jobs:
type=semver,pattern={{major}}
type=sha,prefix=git-,format=short
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push an image to DockerHub
uses: int128/kaniko-action@v1
- name: Build and push
uses: docker/bake-action@v2
with:
push: true
file: deploy/prod/Dockerfile
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: build
591 changes: 0 additions & 591 deletions .yarn/releases/yarn-3.0.0-rc.2.cjs

This file was deleted.

801 changes: 801 additions & 0 deletions .yarn/releases/yarn-3.2.4.cjs

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
packageExtensions:
"html-to-pdf@*":
dependencies:
# those below are needed for "@sentry/node" but it did not work specifying it for sentry
# so it's configured for main package for now
tslib: "*"
cookie: "*"
debug@*:
dependencies:
supports-color: "*"
html-to-pdf@*:
dependencies:
cookie: "*"
tslib: "*"
ws@*:
dependencies:
bufferutil: "*"
utf-8-validate: "*"

yarnPath: .yarn/releases/yarn-3.0.0-rc.2.cjs
yarnPath: .yarn/releases/yarn-3.2.4.cjs
7 changes: 6 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ vars:
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh";
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh";
nvm use;
COMPOSE: docker-compose --file deploy/docker-compose.yml --file deploy/docker-compose.private.yml
COMPOSE: docker-compose --file deploy/docker-compose.yml

tasks:
default: task --list
Expand Down Expand Up @@ -82,3 +82,8 @@ tasks:
desc: Build app locally
cmds:
- bash -c '{{ .NODE_ENV }} yarn build'

build:
desc: Build app image
cmds:
- '{{ .COMPOSE }} build {{ .CLI_ARGS }}'
77 changes: 77 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
FROM node:16-alpine as builder

WORKDIR /app
COPY . /app

RUN yarn install && yarn build


FROM alpine:3.16 as prod

ARG RELEASE_ID
ARG CI_BUILD_DATE

ENV \
CHROME_BIN=/usr/bin/chromium-browser \
CHROME_PATH=/usr/lib/chromium/ \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \
RELEASE_ID=$RELEASE_ID \
CI_BUILD_DATE=$CI_BUILD_DATE

# Installs latest Chromium package.
RUN \
apk upgrade --no-cache --available \
&& apk add --no-cache \
chromium \
ttf-freefont \
font-noto-emoji \
&& apk add --no-cache \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \
font-wqy-zenhei \
&& apk add --no-cache \
tini make gcc g++ python3 git nodejs npm yarn \
&& mkdir -p /app/build \
&& adduser -D chrome \
&& chown -R chrome:chrome /app

WORKDIR /app

COPY deploy/local.conf /etc/fonts/local.conf
COPY --from=builder /app/build/main.prod.js .
COPY favicon.ico .
COPY deploy/docker-entrypoint.sh /docker-entrypoint.sh
COPY README.md .

# Run Chrome as non-privileged
USER chrome

ENTRYPOINT ["tini", "--"]

EXPOSE 4000
CMD ["/docker-entrypoint.sh"]


FROM prod as dev

# change user to bypass write limitations
USER root

COPY . /app

RUN chown -R chrome ./

# change user back to one used by zenika image
USER chrome

RUN yarn install


FROM prod as test

# change user to bypass write limitations
USER root

COPY . /app

RUN yarn
18 changes: 0 additions & 18 deletions deploy/dev/Dockerfile

This file was deleted.

3 changes: 2 additions & 1 deletion deploy/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ services:
image: muehlemann-popp/html-to-pdf-test
build:
context: ../
dockerfile: deploy/test/Dockerfile
dockerfile: deploy/Dockerfile
target: test
container_name: html-to-pdf-test
command: yarn test
environment:
Expand Down
3 changes: 2 additions & 1 deletion deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ services:
image: muehlemann-popp/html-to-pdf
build:
context: ../
dockerfile: deploy/dev/Dockerfile
dockerfile: deploy/Dockerfile
target: dev
volumes:
- '../src/:/app/src/'
container_name: html-to-pdf
Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions deploy/local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

<alias>
<family>sans-serif</family>
<prefer>
<family>Main sans-serif font name goes here</family>
<family>Noto Color Emoji</family>
<family>Noto Emoji</family>
</prefer>
</alias>

<alias>
<family>serif</family>
<prefer>
<family>Main serif font name goes here</family>
<family>Noto Color Emoji</family>
<family>Noto Emoji</family>
</prefer>
</alias>

<alias>
<family>monospace</family>
<prefer>
<family>Main monospace font name goes here</family>
<family>Noto Color Emoji</family>
<family>Noto Emoji</family>
</prefer>
</alias>
</fontconfig>
29 changes: 0 additions & 29 deletions deploy/prod/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions deploy/test/Dockerfile

This file was deleted.

12 changes: 12 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target "docker-metadata-action" {}

target "build" {
inherits = ["docker-metadata-action"]
context = "./"
dockerfile = "deploy/prod/Dockerfile"
platforms = [
"linux/386",
"linux/amd64",
"linux/arm64/v8",
]
}
2 changes: 1 addition & 1 deletion src/controller/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const logException = async <T> (when: string, process: () => Promise<T>):
} catch (e) {
const err = e as Error
// eslint-disable-next-line no-console
console.error(`[${timestamp()}] Exception at ${when}: "${e.message}"`)
console.error(`[${timestamp()}] Exception at ${when}: "${err.message}"`)
// catching errors to sentry is done at higher level, exception stack logging as well
throw err
}
Expand Down
9 changes: 5 additions & 4 deletions webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Configuration } from 'webpack'
import { Configuration, optimize } from 'webpack'
import { resolve } from 'path'
import TerserPlugin from 'terser-webpack-plugin'

Expand Down Expand Up @@ -36,9 +36,10 @@ const config: Configuration = {
optimization: {
minimizer: [new TerserPlugin({ extractComments: false })],
},
// we better bundle everything into 1 script file to ease docker image creation, thus commented out below
externals: [
isProdBuild ? {} : /^[a-z\-0-9]+$/, // Ignore node_modules folder
plugins: [
new optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
],
}

Expand Down
Loading

0 comments on commit 1c7825d

Please sign in to comment.