Build a container on Gitlab CI quest
Game Walkthrough
Serge Matveenko
Slide 2
Slide 2 text
Quest A quest is a journey toward a
specific mission or a goal.
From Wikipedia, the free
encyclopedia
Slide 3
Slide 3 text
Why containers
at all?
Previously on
Building a container image
● Reproducible builds
● Predicted deployments
● OS (distro) independent
● Unified packaging
● Unified infrastructure
● Scalability, orchestration, etc
Slide 4
Slide 4 text
Building a
container image
Goals
● Do not break the existing
workflow
● Container image is the primary
build artifact
● Predicted build behavior
● Effective resources utilization
● Time!
Slide 5
Slide 5 text
Workflow
● Know your workflow:
git{,hub,lab} flow, release
policy, etc
● Use registry path for branches
● Use image tags for tags
● Use suffixes for build variants
Naming container images
Slide 6
Slide 6 text
Naming container images — git[lab] flow
● branch:master — the main integration branch
● branch: — feature/issue branches
● branch:release- — release series support branches
● tag:release- — specific release tags
Slide 7
Slide 7 text
Naming container images — git[lab] flow
● branch:master — the main integration branch
registry.gitlab.com//:latest
before_script:
- export CONTAINER_IMAGE="$CI_REGISTRY_IMAGE:latest"
Naming container images — git[lab] flow
● branch:master — the main integration branch
● branch: — feature/issue branches
● branch:release- — release series support branches
● tag:release- — specific release tags
registry.gitlab.com//[/]:[]
done.
Slide 16
Slide 16 text
Naming container images — build variants
Dockerfile
FROM python as base
WORKDIR /usr/src/app
RUN pipenv install --deploy
FROM base as base-dev
RUN pipenv install --deploy --dev
FROM base as app
COPY ./app ./app
FROM base-dev as dev
COPY . .
Slide 17
Slide 17 text
Naming container images — build variants
Dockerfile
FROM python as base
WORKDIR /usr/src/app
RUN pipenv install --deploy
FROM base as base-dev
RUN pipenv install --deploy --dev
FROM base as app
COPY ./app ./app
FROM base-dev as dev
COPY . .
Resources ● Optimize Dockerfiles
● Local builder cache
● Prepopulate cache
● Use shared builder
Utilizing build cache
Slide 21
Slide 21 text
Utilizing build cache — Dockerfile
FROM python as base
WORKDIR /usr/src/app
COPY ./Pipfile ./Pipfile.lock ./
RUN pipenv install --deploy
FROM base as base-dev
RUN pipenv install --deploy --dev
FROM base as app
COPY ./app ./app
FROM base-dev as dev
COPY . .
Slide 22
Slide 22 text
Utilizing build cache — Local builder cache
FROM python as base
WORKDIR /usr/src/app
COPY ./Pipfile ./Pipfile.lock ./
RUN pipenv install --deploy
FROM base as base-dev
RUN pipenv install --deploy --dev
FROM base as app
COPY ./app ./app
FROM base-dev as dev
COPY . .
Slide 23
Slide 23 text
Utilizing build cache — Local builder cache
Use `buildkit`.
Build Enhancements for Docker — https://docs.docker.com/develop/develop-images/build_enhancements/
Extra
● Use a hash while building a
container instead of `latest`
● Use buildkit if it works for you
● Use LFS for big data and mount it
instead of caring it with an image
● Use multi-target builds
Some do’s don'ts