Skip to content

Commit

Permalink
chore(core): Docker build 缩小 image size 更新github action (DIYgod#7197)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengkx authored Aug 12, 2021
1 parent 2715e65 commit c412846
Show file tree
Hide file tree
Showing 8 changed files with 645 additions and 64 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: master
paths:
- 'lib/**'
- '.github/workflows/**'
- 'Dockerfile'
- 'package.json'

Expand All @@ -13,21 +14,20 @@ jobs:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Dockerhub login
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
-
name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest
name: Checkout
uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build dockerfile (with push)
env:
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@ on:
push:
branches: '*'
paths:
- '.github/workflows/**'
- 'lib/**'
- 'Dockerfile'
- 'package.json'

jobs:
test:
if: github.repository == 'DIYgod/RSSHub'
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build dockerfile (without push)
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ coverage
.env
yarn.lock

.now
.now
.vercel
53 changes: 34 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
FROM node:14-slim
FROM node:14-slim as dep-builder

LABEL MAINTAINER https://github.com/DIYgod/RSSHub/


ENV NODE_ENV production
ENV TZ Asia/Shanghai

ARG USE_CHINA_NPM_REGISTRY=0;
ARG PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1;

RUN ln -sf /bin/bash /bin/sh

RUN apt-get update && apt-get install -yq libgconf-2-4 apt-transport-https git dumb-init python make g++ build-essential --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -yq libgconf-2-4 apt-transport-https git dumb-init python build-essential --no-install-recommends

WORKDIR /app

COPY package.json tools/clean-nm.sh /app/
COPY . /app

RUN if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
echo 'use npm mirror'; npm config set registry https://registry.npm.taobao.org; \
fi;

RUN npm i -g npm

RUN if [ "$PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" = 0 ]; then \
apt-get install -y wget --no-install-recommends \
unset PUPPETEER_SKIP_CHROMIUM_DOWNLOAD && npm install ;\
else \
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true && npm install ;\
fi;

RUN node tools/minify-docker.js

FROM node:14-slim as app

ENV NODE_ENV production
ENV TZ Asia/Shanghai
ARG PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1;

WORKDIR /app
COPY . /app
COPY --from=dep-builder /app/node_modules /app/node_modules
COPY --from=dep-builder /usr/bin/dumb-init /usr/bin/dumb-init

RUN if [ "$PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" = 0 ]; then \
apt-get update \
&& apt-get install -y wget gnupg ca-certificates --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& set -ex \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
ca-certificates \
fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 \
libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 \
libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 \
libxrender1 libxss1 libxtst6 lsb-release \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y wget\
&& rm -rf /src/*.deb \
&& npm install --production && sh ./clean-nm.sh;\
else \
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true && \
npm install --production && sh ./clean-nm.sh;\
&& apt-get purge --auto-remove -y wget gnupg; \
fi;

COPY . /app

EXPOSE 1200
ENTRYPOINT ["dumb-init", "--"]

Expand Down
Loading

0 comments on commit c412846

Please sign in to comment.