Simplify build process
This commit is contained in:
parent
524c42544d
commit
82842c60d8
2 changed files with 6 additions and 26 deletions
11
.build.yml
11
.build.yml
|
@ -9,8 +9,6 @@ secrets:
|
|||
- 5c948915-48c2-4542-8fc1-a5676f4d7126
|
||||
environment:
|
||||
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
|
||||
BLOG_LATEST: rg.fr-par.scw.cloud/crocmagnon/blog:latest
|
||||
tasks:
|
||||
|
@ -20,21 +18,14 @@ tasks:
|
|||
docker login rg.fr-par.scw.cloud/crocmagnon -u nologin --password-stdin < .docker-secret
|
||||
cd blog
|
||||
docker pull $BLOG_LATEST || true
|
||||
docker pull $BLOG_TESTS || 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 prod --cache-from $BLOG_LATEST --cache-from $DEPS_LATEST -t $BLOG_LATEST -f Dockerfile .
|
||||
|
||||
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 run --rm -t $BLOG_LATEST /app/docker/runtests.sh
|
||||
|
||||
docker push $BLOG_LATEST
|
||||
docker push $DEPS_LATEST
|
||||
docker push $DEPS_TESTS
|
||||
docker push $BLOG_TESTS
|
||||
- deploy: |
|
||||
ssh blog -o StrictHostKeyChecking=no "/home/gaugendre/blog/redeploy"
|
||||
triggers:
|
||||
|
|
21
Dockerfile
21
Dockerfile
|
@ -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)" \
|
||||
&& 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) \
|
||||
&& poetry install --no-dev
|
||||
&& poetry install
|
||||
|
||||
|
||||
## Get git versions
|
||||
|
@ -30,7 +30,10 @@ RUN git rev-parse HEAD | tee /version
|
|||
## Beginning of runtime image
|
||||
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
|
||||
|
||||
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)"
|
||||
|
||||
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/
|
||||
|
|
Reference in a new issue