Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kubespray
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Kubespray
Commits
3378c9f3
Unverified
Commit
3378c9f3
authored
1 year ago
by
Luke Simmons
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Use caching to speed up docker build (#10008)
parent
4c820b85
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci/build.yml
+35
-11
35 additions, 11 deletions
.gitlab-ci/build.yml
pipeline.Dockerfile
+6
-6
6 additions, 6 deletions
pipeline.Dockerfile
with
41 additions
and
17 deletions
.gitlab-ci/build.yml
+
35
−
11
View file @
3378c9f3
---
---
pipeline image
:
.build
:
stage
:
build
stage
:
build
image
:
docker:20.10.22-cli
image
:
name
:
moby/buildkit:rootless
entrypoint
:
[
"
"
]
variables
:
variables
:
DOCKER_TLS_CERTDIR
:
"
"
BUILDKITD_FLAGS
:
--oci-worker-no-process-sandbox
services
:
-
name
:
docker:20.10.22-dind
# See https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300 for why this is required
command
:
[
"
--tls=false"
]
before_script
:
before_script
:
-
echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
-
mkdir ~/.docker
-
echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > ~/.docker/config.json
pipeline image
:
extends
:
.build
script
:
-
|
buildctl-daemonless.sh build \
--frontend=dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--opt filename=./pipeline.Dockerfile \
--output type=image,name=$PIPELINE_IMAGE,push=true \
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/pipeline:cache
rules
:
-
if
:
'
$CI_COMMIT_REF_NAME
!=
$CI_DEFAULT_BRANCH'
pipeline image and build cache
:
extends
:
.build
script
:
script
:
# DOCKER_HOST is overwritten if we set it as a GitLab variable
-
|
-
DOCKER_HOST=tcp://docker:2375; docker build --network host --file pipeline.Dockerfile --tag $PIPELINE_IMAGE .
buildctl-daemonless.sh build \
-
docker push $PIPELINE_IMAGE
--frontend=dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--opt filename=./pipeline.Dockerfile \
--output type=image,name=$PIPELINE_IMAGE,push=true \
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/pipeline:cache \
--export-cache type=registry,ref=$CI_REGISTRY_IMAGE/pipeline:cache,mode=max
rules
:
-
if
:
'
$CI_COMMIT_REF_NAME
==
$CI_DEFAULT_BRANCH'
This diff is collapsed.
Click to expand it.
pipeline.Dockerfile
+
6
−
6
View file @
3378c9f3
...
@@ -36,11 +36,13 @@ RUN apt update -q \
...
@@ -36,11 +36,13 @@ RUN apt update -q \
&&
apt autoremove
-yqq
--purge
&&
apt clean
&&
rm
-rf
/var/lib/apt/lists/
*
/var/log/
*
&&
apt autoremove
-yqq
--purge
&&
apt clean
&&
rm
-rf
/var/lib/apt/lists/
*
/var/log/
*
WORKDIR
/kubespray
WORKDIR
/kubespray
COPY
. .
RUN
update-alternatives
--install
/usr/bin/python python /usr/bin/python3 1
\
RUN
--mount
=
type
=
bind
,target
=
./requirements-2.12.txt,src
=
./requirements-2.12.txt
\
--mount
=
type
=
bind
,target
=
./tests/requirements-2.12.txt,src
=
./tests/requirements-2.12.txt
\
--mount
=
type
=
bind
,target
=
./roles/kubespray-defaults/defaults/main.yaml,src
=
./roles/kubespray-defaults/defaults/main.yaml
\
update-alternatives
--install
/usr/bin/python python /usr/bin/python3 1
\
&&
pip
install
--no-compile
--no-cache-dir
pip
-U
\
&&
pip
install
--no-compile
--no-cache-dir
pip
-U
\
&&
pip
install
--no-compile
--no-cache-dir
-r
tests/requirements
.txt
-r
requirements
.txt
\
&&
pip
install
--no-compile
--no-cache-dir
-r
tests/requirements
-2.12
.txt
\
&&
KUBE_VERSION
=
$(
sed
-n
's/^kube_version: //p'
roles/kubespray-defaults/defaults/main.yaml
)
\
&&
KUBE_VERSION
=
$(
sed
-n
's/^kube_version: //p'
roles/kubespray-defaults/defaults/main.yaml
)
\
&&
curl
-L
https://storage.googleapis.com/kubernetes-release/release/
$KUBE_VERSION
/bin/linux/
$(
dpkg
--print-architecture
)
/kubectl
-o
/usr/local/bin/kubectl
\
&&
curl
-L
https://storage.googleapis.com/kubernetes-release/release/
$KUBE_VERSION
/bin/linux/
$(
dpkg
--print-architecture
)
/kubectl
-o
/usr/local/bin/kubectl
\
&&
echo
$(
curl
-L
https://storage.googleapis.com/kubernetes-release/release/
$KUBE_VERSION
/bin/linux/
$(
dpkg
--print-architecture
)
/kubectl.sha256
)
/usr/local/bin/kubectl |
sha256sum
--check
\
&&
echo
$(
curl
-L
https://storage.googleapis.com/kubernetes-release/release/
$KUBE_VERSION
/bin/linux/
$(
dpkg
--print-architecture
)
/kubectl.sha256
)
/usr/local/bin/kubectl |
sha256sum
--check
\
...
@@ -52,6 +54,4 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
...
@@ -52,6 +54,4 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
&& vagrant plugin install vagrant-libvirt \
&& vagrant plugin install vagrant-libvirt \
# Install Kubernetes collections
# Install Kubernetes collections
&& pip install --no-compile --no-cache-dir kubernetes \
&& pip install --no-compile --no-cache-dir kubernetes \
&& ansible-galaxy collection install kubernetes.core \
&& ansible-galaxy collection install kubernetes.core
# Clean cache python
&& find / -type d -name '*__pycache__' -prune -exec rm -rf {} \;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment