Skip to content

Commit

Permalink
fix(ci): Make all vector dev volumnes unique
Browse files Browse the repository at this point in the history
For running multiple jobs in CI, it will help to have all volumes be
owned by whatever branch is running. Similar to `VECTOR_TARGET`, add a
dynamic volume name for rust and cargo caches. Clean up those volumes
upon CI exit by calling `environment-clean` which will also remove any
stopped/unused containers.

Ref: LOG-19643
  • Loading branch information
darinspivey committed Apr 8, 2024
1 parent c8a2366 commit ee0749c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
60 changes: 32 additions & 28 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,19 @@ pipeline {
ENVIRONMENT_AUTOBUILD = 'false'
ENVIRONMENT_TTY = 'false'
CI = 'true'
VECTOR_TARGET = "${BRANCH_BUILD}"
VECTOR_TARGET = "${BRANCH_BUILD}-target"
VECTOR_CARGO_CACHE = "${BRANCH_BUILD}-cargo"
VECTOR_RUSTUP_CACHE = "${BRANCH_BUILD}-rustup"
}
stages {
stage('Setup') {
stage('Release Tool') {
steps {
sh 'make release-tool'
}
}
stage('Check'){
// Important: do this step serially since it'll be the one to prepare the testing container
// and install the rust toolchain in it. Volume mounts are created here, too.
steps {
sh """
make check ENVIRONMENT=true
make check-fmt ENVIRONMENT=true
"""
}
}
stage('Lint and test release'){
tools {
nodejs 'NodeJS 16'
nodejs 'NodeJS 20'
}
environment {
GIT_BRANCH = "${CURRENT_BRANCH}"
Expand All @@ -94,18 +86,37 @@ pipeline {
sh './release-tool test'
}
}
stage('Lint and Test') {
stage('Unit test'){
// Important: do one step serially since it'll be the one to prepare the testing container
// and install the rust toolchain in it. Volume mounts are created here, too.
steps {
sh """
make test ENVIRONMENT=true
"""
}
}
stage('Checks') {
// All `make ENVIRONMENT=true` steps should now use the existing container
parallel {
stage('Lint'){
stage('check-clippy'){
steps {
sh """
make check-clippy ENVIRONMENT=true
make check-scripts ENVIRONMENT=true
"""
}
}
stage('Deny'){
stage('check-fmt'){
// Important: do this step serially since it'll be the one to prepare the testing container
// and install the rust toolchain in it. Volume mounts are created here, too.
steps {
sh """
make check ENVIRONMENT=true
make check-fmt ENVIRONMENT=true
"""
}
}
stage('check-deny'){
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh """
Expand All @@ -114,14 +125,7 @@ pipeline {
}
}
}
stage('Unit test'){
steps {
sh """
make test ENVIRONMENT=true
"""
}
}
stage('Test build container image') {
stage('image test') {
when {
changeRequest() // Only do this during PRs because it can take 30 minutes
}
Expand Down Expand Up @@ -167,7 +171,7 @@ pipeline {
}
}
tools {
nodejs 'NodeJS 16'
nodejs 'NodeJS 20'
}
steps {
script {
Expand Down Expand Up @@ -196,9 +200,9 @@ pipeline {
}
post {
always {
// Clear disk space by removing the `target` volume mount where the binaries are stored.
// The volume is unique to the current build, so there should be no "in use" errors.
sh 'make target-clean'
// Clear disk space by removing the test container and all of its volumes.
// The container and volumes are unique to the current build, so there should be no "in use" errors.
sh 'make environment-clean'

script {
if (env.SANITY_BUILD == 'true') {
Expand Down
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export VERSION ?= $(shell command -v cargo >/dev/null && cargo vdev version || e
export CI ?= false

export VECTOR_TARGET ?= vector-target
export VECTOR_CARGO_CACHE ?= vector-cargo-cache
export VECTOR_RUSTUP_CACHE ?= vector-rustup-cache

export RUST_VERSION ?= $(shell grep channel rust-toolchain.toml | cut -d '"' -f 2)

Expand Down Expand Up @@ -149,6 +151,7 @@ BUILD_TAG ?=
CONTAINER_ID = vector-environment-$(shell echo $(BUILD_TAG) | sed -E 's/[^a-zA-Z0-9_.-]/-/g')$(shell date +%s)-$(shell echo $$PPID)

# We use a volume here as non-Linux hosts are extremely slow to share disks, and Linux hosts tend to get permissions clobbered.
# Note that `--rm` does not remove named volumes, so these will provide caching until removed with `evironment-clean`
define ENVIRONMENT_EXEC
${ENVIRONMENT_PREPARE}
@echo "Entering environment..."
Expand All @@ -167,8 +170,8 @@ define ENVIRONMENT_EXEC
--mount type=bind,source=${CURRENT_DIR}/scripts/environment/entrypoint.sh,target=/entrypoint.sh \
$(if $(findstring docker,$(CONTAINER_TOOL)),--mount type=bind$(COMMA)source=/var/run/docker.sock$(COMMA)target=/var/run/docker.sock,) \
--mount type=volume,source=${VECTOR_TARGET},target=/git/vectordotdev/vector/target \
--mount type=volume,source=vector-cargo-cache,target=/root/.cargo \
--mount type=volume,source=vector-rustup-cache,target=/root/.rustup \
--mount type=volume,source=${VECTOR_CARGO_CACHE},target=/root/.cargo \
--mount type=volume,source=${VECTOR_RUSTUP_CACHE},target=/root/.rustup \
$(foreach publish,$(ENVIRONMENT_PUBLISH),--publish $(publish)) \
$(ENVIRONMENT_UPSTREAM)
endef
Expand Down Expand Up @@ -210,14 +213,17 @@ environment:
environment-prepare: ## Prepare the Vector dev shell using $CONTAINER_TOOL.
${ENVIRONMENT_PREPARE}

.PHONY: target-clean
target-clean: ## Clean just the target volume, and leave toolchain/cargo in tact
@echo "Removing vector target volume: ${VECTOR_TARGET}"
@$(CONTAINER_TOOL) volume rm -f ${VECTOR_TARGET}

.PHONY: environment-clean
environment-clean: ## Clean the Vector dev shell using $CONTAINER_TOOL.
@$(CONTAINER_TOOL) volume rm -f ${VECTOR_TARGET} vector-cargo-cache vector-rustup-cache
@echo "\nList of active volumes"
@$(CONTAINER_TOOL) volume ls
@echo "\nList of all containers"
@$(CONTAINER_TOOL) ps -a
@echo "\nRemoving vector dev volumes"
@$(CONTAINER_TOOL) volume rm -f ${VECTOR_TARGET} ${VECTOR_CARGO_CACHE} ${VECTOR_RUSTUP_CACHE}
@echo "\nRemoving stopped containers"
@$(CONTAINER_TOOL) container prune
@echo "\nRemoving vector dev image (if possible)"
@$(CONTAINER_TOOL) rmi $(ENVIRONMENT_UPSTREAM) || true

.PHONY: environment-push
Expand Down

0 comments on commit ee0749c

Please sign in to comment.