Dockerfile 4.0 KB
Newer Older
1
FROM ubuntu:17.10
2 3 4
LABEL maintainer="Huan LI <zixia@zixia.net>"

ENV DEBIAN_FRONTEND     noninteractive
5
ENV WECHATY_DOCKER      1
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6 7 8
ENV LC_ALL              C.UTF-8
ENV NODE_ENV            $NODE_ENV
ENV NPM_CONFIG_LOGLEVEL warn
9 10 11 12 13 14 15

# Installing the 'apt-utils' package gets rid of the 'debconf: delaying package configuration, since apt-utils is not installed'
# error message when installing any other package with the apt-get package manager.
# https://peteris.rocks/blog/quiet-and-unattended-installation-with-apt-get/
RUN apt-get update && apt-get install -y --no-install-recommends \
    apt-utils \
    bash \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
16
    build-essential \
17 18 19 20
    ca-certificates \
    curl \
    coreutils \
    figlet \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
21
    git \
22 23 24
    jq \
    libav-tools \
    moreutils \
25
    shellcheck \
26 27
    sudo \
    ttf-freefont \
28
    tzdata \
29
    vim \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
30
    wget \
31 32
  && apt-get purge --auto-remove \
  && rm -rf /tmp/* /var/lib/apt/lists/*
33 34 35

RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
    && apt-get update && apt-get install -y --no-install-recommends nodejs \
36 37
    && apt-get purge --auto-remove \
    && rm -rf /tmp/* /var/lib/apt/lists/*
38 39 40 41 42

# https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
# https://github.com/ebidel/try-puppeteer/blob/master/backend/Dockerfile
# Install latest chrome dev package.
# Note: this also installs the necessary libs so we don't need the previous RUN command.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
43
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
44
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
45 46
    && apt-get update && apt-get install -y --no-install-recommends \
      google-chrome-unstable \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
47
    && apt-get purge --auto-remove \
48 49
    && rm -rf /tmp/* /var/lib/apt/lists/* \
    && rm -rf /usr/bin/google-chrome* /opt/google/chrome-unstable
50 51

# Add chatie user.
52
RUN groupadd -r bot && useradd -r -m -G audio,video,sudo -g bot -d /bot bot \
53 54
    && mkdir -p /bot/Downloads \
    && chown -R bot:bot /bot \
55
    && echo "bot ALL=NOPASSWD:ALL" >> /etc/sudoers
56

57 58 59
RUN mkdir /wechaty \
    && chown -R bot:bot /wechaty \
    && mkdir /node_modules
60

61
WORKDIR /wechaty
62 63 64

# Run user as non privileged.
USER bot
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
65

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
66
COPY package.json .
67
RUN npm install \
68
  && sudo rm -fr /tmp/* ~/.npm
69

70
COPY . .
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
71 72
RUN npm run test \
  && npm run dist
73

74 75 76 77 78
# Loading from node_modules Folders: https://nodejs.org/api/modules.html
# If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached.
RUN sudo npm link \
    && sudo ln -s /wechaty /node_modules/wechaty \
    && sudo ln -s /wechaty/node_modules/* /node_modules/ \
79
    && sudo ln -s /wechaty/node_modules/.bin/* /usr/local/bin/ \
80 81
    && sudo ln -s /wechaty/tsconfig.json / \
    && echo "export * from 'wechaty'" | sudo tee /index.ts \
82
    && echo 'Linked Wechaty to Global'
83

84 85
ENTRYPOINT  [ "/wechaty/bin/entrypoint.sh" ]
CMD         [ "" ]
86

87 88 89 90
#
# https://docs.docker.com/docker-cloud/builds/advanced/
# http://label-schema.org/rc1/
#
91
LABEL org.label-schema.license="Apache-2.0" \
92 93 94 95 96
      org.label-schema.build-date="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
      org.label-schema.version="$DOCKER_TAG" \
      org.label-schema.schema-version="$(wechaty-version)" \
      org.label-schema.name="Wechaty" \
      org.label-schema.description="Wechat for Bot" \
97
      org.label-schema.usage="https://github.com/chatie/wechaty/wiki/Docker" \
98
      org.label-schema.url="https://www.chatie.io" \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
99
      org.label-schema.vendor="Chatie" \
100
      org.label-schema.vcs-ref="$SOURCE_COMMIT" \
101
      org.label-schema.vcs-url="https://github.com/chatie/wechaty" \
102 103 104
      org.label-schema.docker.cmd="docker run -ti --rm zixia/wechaty <code.js>" \
      org.label-schema.docker.cmd.test="docker run -ti --rm zixia/wechaty test" \
      org.label-schema.docker.cmd.help="docker run -ti --rm zixia/wechaty help" \
105
      org.label-schema.docker.params="WECHATY_TOKEN=token token from https://www.chatie.io, WECHATY_LOG=verbose Set Verbose Log, TZ='Asia/Shanghai' TimeZone"
106