Optimize CI and dockerfile caching

This commit is contained in:
Tulir Asokan 2020-02-26 00:42:06 +02:00
parent 293b44729c
commit 9a777ee451
3 changed files with 85 additions and 26 deletions

View File

@ -1,6 +1,7 @@
image: docker:stable
stages:
- build frontend
- build
- manifest
@ -8,13 +9,33 @@ default:
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build frontend:
image: node:lts-alpine
stage: build frontend
before_script: []
variables:
NODE_ENV: "production"
cache:
paths:
- maubot/management/frontend/node_modules
script:
- cd maubot/management/frontend
- yarn --prod
- yarn build
- mv build ../../../frontend
artifacts:
paths:
- frontend
expire_in: 1 hour
build amd64:
stage: build
tags:
- amd64
script:
- echo frontend >> .dockerignore
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 .
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 . -f Dockerfile.ci
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64
@ -23,8 +44,9 @@ build arm64:
tags:
- arm64
script:
- echo frontend >> .dockerignore
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 .
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 . -f Dockerfile.ci
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64

View File

@ -5,33 +5,36 @@ RUN cd /frontend && yarn --prod && yarn build
FROM alpine:3.11
ENV UID=1337 \
GID=1337
COPY requirements.txt /opt/maubot/requirements.txt
WORKDIR /opt/maubot
RUN apk add --no-cache --virtual .build-deps \
python3-dev \
build-base \
git \
&& apk add --no-cache \
ca-certificates \
su-exec \
py3-aiohttp \
py3-sqlalchemy \
py3-attrs \
py3-bcrypt \
py3-cffi \
py3-pillow \
py3-magic \
py3-psycopg2 \
py3-ruamel.yaml \
py3-jinja2 \
py3-click \
py3-packaging \
py3-markdown \
&& pip3 install -r requirements.txt \
feedparser dateparser langdetect python-gitlab \
&& apk del .build-deps
# TODO remove pillow, magic and feedparser when maubot supports installing dependencies
COPY . /opt/maubot
COPY --from=frontend-builder /frontend/build /opt/maubot/frontend
WORKDIR /opt/maubot
RUN apk add --no-cache \
py3-aiohttp \
py3-sqlalchemy \
py3-attrs \
py3-bcrypt \
py3-cffi \
build-base \
python3-dev \
ca-certificates \
su-exec \
py3-pillow \
py3-magic \
py3-psycopg2 \
py3-ruamel.yaml \
py3-jinja2 \
py3-click \
py3-packaging \
py3-markdown \
&& pip3 install -r requirements.txt feedparser dateparser langdetect python-gitlab
# TODO remove pillow, magic and feedparser when maubot supports installing dependencies
ENV UID=1337 GID=1337
VOLUME /data
CMD ["/opt/maubot/docker/run.sh"]

34
Dockerfile.ci Normal file
View File

@ -0,0 +1,34 @@
FROM alpine:3.11
COPY requirements.txt /opt/maubot/requirements.txt
WORKDIR /opt/maubot
RUN apk add --no-cache --virtual .build-deps \
python3-dev \
build-base \
git \
&& apk add --no-cache \
ca-certificates \
su-exec \
py3-aiohttp \
py3-sqlalchemy \
py3-attrs \
py3-bcrypt \
py3-cffi \
py3-pillow \
py3-magic \
py3-psycopg2 \
py3-ruamel.yaml \
py3-jinja2 \
py3-click \
py3-packaging \
py3-markdown \
&& pip3 install -r requirements.txt \
feedparser dateparser langdetect python-gitlab \
&& apk del .build-deps
# TODO remove pillow, magic and feedparser when maubot supports installing dependencies
COPY . /opt/maubot
ENV UID=1337 GID=1337
VOLUME /data
CMD ["/opt/maubot/docker/run.sh"]