Last active
July 15, 2019 13:53
-
-
Save jefftriplett/09835389fe4426dfb04299299fbadd90 to your computer and use it in GitHub Desktop.
A GitLab CI workflow inspired by: https://www.digitalocean.com/community/tutorials/how-to-build-docker-images-and-host-a-docker-image-repository-with-gitlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: docker:latest | |
services: | |
- docker:dind | |
- postgres:latest | |
stages: | |
- build | |
- test | |
- release | |
variables: | |
PYTHONDONTWRITEBYTECODE: 1 | |
PYTHONUNBUFFERED: 1 | |
RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest | |
TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME | |
before_script: | |
- docker version | |
- docker info | |
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY | |
build: | |
stage: build | |
script: | |
- docker pull $CI_REGISTRY_IMAGE:latest || true | |
- docker build -f .docker/Dockerfile --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $TEST_IMAGE . | |
# - docker build -f .docker/Dockerfile --pull -t $TEST_IMAGE . | |
- docker push $TEST_IMAGE | |
test: | |
stage: test | |
variables: | |
DATABASE_URL: "postgres://postgres@postgres/postgres" | |
POSTGRES_DB: postgres | |
POSTGRES_PASSWORD: "" | |
POSTGRES_USER: postgres | |
script: | |
- docker run -d -e POSTGRES_DB -e POSTGRES_USER -e POSTGRES_PASSWORD --name postgres postgres:10 | |
- docker pull $TEST_IMAGE | |
- docker run -e DATABASE_URL --link postgres $TEST_IMAGE pytest | |
release: | |
stage: release | |
script: | |
- docker pull $TEST_IMAGE | |
- docker tag $TEST_IMAGE $RELEASE_IMAGE | |
- docker push $RELEASE_IMAGE | |
only: | |
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.7-stretch | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
ENV PYTHONUNBUFFERED 1 | |
COPY requirements.txt /src/ | |
RUN set -ex && \ | |
pip install --no-cache-dir \ | |
-r /src/requirements.txt && \ | |
rm -rf /root/.cache | |
COPY . /src/ | |
WORKDIR /src/ | |
ENTRYPOINT ["/src/docker-entrypoint.sh", "--"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eo pipefail | |
python manage.py migrate --noinput | |
python manage.py collectstatic --noinput | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment