Simplify build process

This commit is contained in:
Gabriel Augendre 2020-11-11 12:10:58 +01:00
parent 524c42544d
commit 82842c60d8
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 6 additions and 26 deletions

View file

@ -9,8 +9,6 @@ secrets:
- 5c948915-48c2-4542-8fc1-a5676f4d7126 - 5c948915-48c2-4542-8fc1-a5676f4d7126
environment: environment:
TESTING: true TESTING: true
DEPS_TESTS: rg.fr-par.scw.cloud/crocmagnon/blog:deps-tests
BLOG_TESTS: rg.fr-par.scw.cloud/crocmagnon/blog:tests
DEPS_LATEST: rg.fr-par.scw.cloud/crocmagnon/blog:deps-latest DEPS_LATEST: rg.fr-par.scw.cloud/crocmagnon/blog:deps-latest
BLOG_LATEST: rg.fr-par.scw.cloud/crocmagnon/blog:latest BLOG_LATEST: rg.fr-par.scw.cloud/crocmagnon/blog:latest
tasks: tasks:
@ -20,21 +18,14 @@ tasks:
docker login rg.fr-par.scw.cloud/crocmagnon -u nologin --password-stdin < .docker-secret docker login rg.fr-par.scw.cloud/crocmagnon -u nologin --password-stdin < .docker-secret
cd blog cd blog
docker pull $BLOG_LATEST || true docker pull $BLOG_LATEST || true
docker pull $BLOG_TESTS || true
docker pull $DEPS_LATEST || true docker pull $DEPS_LATEST || true
docker pull $DEPS_TESTS || true
docker build --pull --target venv --cache-from $DEPS_LATEST -t $DEPS_LATEST . docker build --pull --target venv --cache-from $DEPS_LATEST -t $DEPS_LATEST .
docker build --pull --target prod --cache-from $BLOG_LATEST --cache-from $DEPS_LATEST -t $BLOG_LATEST -f Dockerfile . docker build --pull --target prod --cache-from $BLOG_LATEST --cache-from $DEPS_LATEST -t $BLOG_LATEST -f Dockerfile .
docker run --rm -t $BLOG_LATEST /app/docker/runtests.sh
docker build --pull --target venv-tests --cache-from $BLOG_LATEST --cache-from $DEPS_LATEST --cache-from $DEPS_TESTS -t $DEPS_TESTS .
docker build --pull --target tests --cache-from $BLOG_LATEST --cache-from $DEPS_LATEST --cache-from $DEPS_TESTS --cache-from $BLOG_TESTS -t $BLOG_TESTS -f Dockerfile .
docker run --rm -t $BLOG_TESTS /app/docker/runtests.sh
docker push $BLOG_LATEST docker push $BLOG_LATEST
docker push $DEPS_LATEST docker push $DEPS_LATEST
docker push $DEPS_TESTS
docker push $BLOG_TESTS
- deploy: | - deploy: |
ssh blog -o StrictHostKeyChecking=no "/home/gaugendre/blog/redeploy" ssh blog -o StrictHostKeyChecking=no "/home/gaugendre/blog/redeploy"
triggers: triggers:

View file

@ -17,7 +17,7 @@ RUN python -m venv --copies /app/venv \
&& (python -c "from poetry.factory import Factory; l = Factory().create_poetry('.').locker; exit(0) if l.is_locked() and l.is_fresh() else exit(1)" \ && (python -c "from poetry.factory import Factory; l = Factory().create_poetry('.').locker; exit(0) if l.is_locked() and l.is_fresh() else exit(1)" \
&& echo "poetry.lock is up to date") \ && echo "poetry.lock is up to date") \
|| (>&2 echo "poetry.lock is outdated. Run `poetry lock` on your machine and commit the file." && exit 1) \ || (>&2 echo "poetry.lock is outdated. Run `poetry lock` on your machine and commit the file." && exit 1) \
&& poetry install --no-dev && poetry install
## Get git versions ## Get git versions
@ -30,7 +30,10 @@ RUN git rev-parse HEAD | tee /version
## Beginning of runtime image ## Beginning of runtime image
FROM python:3.8.6-slim-buster as prod FROM python:3.8.6-slim-buster as prod
RUN echo "Europe/Paris" > /etc/timezone \ RUN apt-get update \
# Git is required for pre-commit checks
&& apt-get install -y --no-install-recommends git \
&& echo "Europe/Paris" > /etc/timezone \
&& mkdir /db && mkdir /db
COPY --from=venv /app/venv /app/venv/ COPY --from=venv /app/venv /app/venv/
@ -52,17 +55,3 @@ ENV DB_BASE_DIR "/db"
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)" HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
CMD ["/app/docker/run.sh"] CMD ["/app/docker/run.sh"]
## Build venv for tests
FROM venv as venv-tests
WORKDIR /app
RUN . /app/venv/bin/activate \
&& poetry install
## Build test image
FROM prod as tests
RUN apt-get update && apt-get install -y --no-install-recommends git
COPY --from=venv-tests /app/venv /app/venv/
COPY .git ./.git/