Skip to content

Commit

Permalink
feat: add font and chromium build
Browse files Browse the repository at this point in the history
  • Loading branch information
amraln authored and amille44420 committed Jul 25, 2022
1 parent abbbf8a commit f941925
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 28 deletions.
42 changes: 42 additions & 0 deletions .github/actions/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Docker build"
description: "Build docker html2pdf-service image by its setting"
inputs:
dockerFile: # Docker filename to build
description: "Dockerfile to build"
required: true
default: "docker/chrome/Dockerfile"
imageName:
description: "Image name for tagging"
required: true
runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- name: Build image
run: docker build . --file ${{ input.dockerFile }} --tag ${{ input.imageName }}

- name: Log into registry
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u $DOCKER_LOGIN --password-stdin

- name: Push image
run: |
IMAGE_ID=appvantage/${{ input.imageName }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag ${{ input.imageName }} $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
38 changes: 10 additions & 28 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,14 @@ jobs:
packages: write

steps:
- uses: actions/checkout@v3

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u $DOCKER_LOGIN --password-stdin

- name: Push image
run: |
IMAGE_ID=appvantage/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
- name: Build image for chrome
uses: ./.github/actions/docker-build
with:
dockerFile: docker/chrome/Dockerfile
imageName: $IMAGE_NAME

docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Build image for chromium
uses: ./.github/actions/docker-build
with:
dockerFile: docker/chromium/Dockerfile
imageName: $IMAGE_NAME-chromium
2 changes: 2 additions & 0 deletions Dockerfile → docker/chrome/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ RUN apt-get update \
# (https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)
# but that seems too easy to get out of date.
&& apt-get install -y google-chrome-stable \
# Font installation, support chinese font characters for now
&& apt-get install -y fonts-wqy-zenhei \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/app
Expand Down
53 changes: 53 additions & 0 deletions docker/chromium/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM node:18.3.0-bullseye-slim as build

RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/app

ENV NODE_ENV=development
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

COPY yarn.lock package.json ./

RUN yarn install --frozen-lockfile

COPY tsconfig.json ./
COPY src ./src

RUN yarn build

ENV NODE_ENV=production

# install dependencies with frozen lockfile
# then clean with node prune
RUN yarn install --frozen-lockfile --production

# install node prune
RUN curl -sf https://gobinaries.com/tj/node-prune | sh

FROM node:18.3.0-bullseye-slim

RUN apt-get update \
&& apt-get install -y wget gnupg ca-certificates procps libxss1 \
&& apt-get update \
# For ARM, google-chrome-stable is not available
# and M1 failed to emulate the chrome browser.
# thus we use chromium for this
&& apt-get install -y chromium \
# Font settings, currently support for chinese characters
&& apt-get install -y fonts-wqy-zenhei \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/app

ENV PORT=3000
ENV NODE_ENV=production
# ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium

COPY --from=build /usr/local/app/node_modules ./node_modules
COPY --from=build /usr/local/app/build ./

CMD node index.js

0 comments on commit f941925

Please sign in to comment.