Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Dockerfile): Refactor dockerfile to Debian Slim with no deps #613

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
110 changes: 75 additions & 35 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,56 @@ variables:
S3_BUCKET_NAME: "mender"
S3_BUCKET_PATH: "mender-artifact"
DOCKER_BUILDKIT: 1
DOCKER_PLATFORMS:
value: "linux/amd64,linux/arm64"
description: "Platforms for building and distributing container images"

test:check-license-source:
variables:
LICENSE_HEADERS_IGNORE_FILES_REGEXP: './artifact/keyfactor/\(signer\|signer_test\)\.go'

build:docker:
image: docker
image: docker:26-cli
needs: []
services:
- docker:dind
- docker:26-dind
stage: build
before_script:
- |
echo ${CI_REGISTRY_PASSWORD} | \
docker login \
--username "$CI_REGISTRY_USER" \
--password-stdin \
"$CI_REGISTRY"
- docker buildx create --platform "$DOCKER_PLATFORMS" --name builder --bootstrap --use
script:
- docker build -t $DOCKER_REPOSITORY:pr .
- docker save $DOCKER_REPOSITORY:pr > image.tar
artifacts:
expire_in: 2w
paths:
- image.tar
- |
docker buildx build --push \
--platform "$DOCKER_PLATFORMS" \
--tag "$CI_REGISTRY_IMAGE:$CI_PIPELINE_IID" \
.
tags:
- gitlab-org-docker

build:make:
image: docker
build:yoctocompat:
# Keep golang version aligned with latest yocto release
image: golang:1.17.13-bullseye
alfrunes marked this conversation as resolved.
Show resolved Hide resolved
needs: []
services:
- docker:dind
before_script:
- apk add --no-cache make
- apt-get update
- apt-get install -qy libssl-dev
script:
- go build

build:make:
image: golang:1.22.4
needs: []
stage: build
before_script:
- apt-get update
- apt-get install -qqy libssl-dev
script:
- make build-natives-contained
- make build-natives
artifacts:
expire_in: 2w
paths:
Expand All @@ -74,20 +93,17 @@ build:make:

build:coverage:
stage: build
image: docker
image: golang:1.22.4
needs: []
services:
- docker:dind
before_script:
- apk add --no-cache make
- make instrument-binary-contained
- apt-get update
- apt-get install -qqy libssl-dev
script:
- make build-contained
- mv mender-artifact mender-artifact-linux-coverage
- make build BUILDFLAGS='-cover'
artifacts:
expire_in: 2w
paths:
- mender-artifact-linux-coverage
- mender-artifact

test:smoketests:mac:
stage: test
Expand All @@ -114,13 +130,12 @@ test:smoketests:mac:

test:smoketests:linux:
stage: test
# Keep golang version aligned with latest yocto release
image: golang:1.17-buster
image: golang:1.22.4
needs:
- job: build:make
artifacts: true
before_script:
- apt-get update && apt-get install -q -y make liblzma-dev libssl-dev
- apt-get update && apt-get install -q -y make libssl-dev
- ./tests/test_sign_with_hsm/test_sign_with_hsm.sh --setup
- export TEST_MENDER_ARTIFACT_PATH=./mender-artifact-linux
script:
Expand All @@ -135,30 +150,25 @@ test:smoketests:linux:
- ./mender-artifact-linux read test-rfs.mender
- ./mender-artifact-linux validate test-rfs.mender
- ./tests/test_compressions/test_supported_compressions.sh
# QA-507: lock mender-artifact to OpenSSL 1.1
- ldd ./mender-artifact-linux | grep libssl.so.1.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not break compatibility this way. We need to plan it a bit. As discussed in person, we could offer two flavors in our Downloads page: one statically linked without pkcs11 and one dynamically linked for openssl3.

As this starts to be bigger than a nice to have PR, can we create a task for it? It involves the work here, plus having some sort of subdirs structure in the S3 bucket, and mender-docs.

- make build

test:coverage:linux:
stage: test
image: debian:buster-slim
image: golang:1.22.4
needs:
- job: build:coverage
artifacts: true
variables:
COVERAGE_FILE: coverage-linux-pkcs.txt
before_script:
- ./tests/test_sign_with_hsm/test_sign_with_hsm.sh --setup
- export TEST_MENDER_ARTIFACT_PATH=./mender-artifact-linux-coverage
- COVERDIR=$(mktemp -d /tmp/cover-XXXX)
- export GOCOVERDIR=${COVERDIR}
- export TEST_MENDER_ARTIFACT_PATH=./mender-artifact
script:
- ./tests/test_sign_with_hsm/test_sign_with_hsm.sh
after_script:
- set -- /tmp/coverage-artifact*.out
- head -n 1 $1 > ${COVERAGE_FILE}
- |
for cover in $@; do
tail -n +2 $cover >> ${COVERAGE_FILE}
done
- go tool covdata textfmt -i ${COVERDIR} -o ${COVERAGE_FILE}
artifacts:
expire_in: 2w
untracked: true
Expand Down Expand Up @@ -260,6 +270,36 @@ publish:s3:
only:
- /^(master|[0-9]+\.[0-9]+\.x)$/

publish:docker:
stage: publish
rules:
- if: '$CI_COMMIT_TAG'
- if: '$CI_COMMIT_BRANCH == "master"'
- when: manual # Fallback; allow manual trigger
allow_failure: true
image:
name: "quay.io/skopeo/stable:v1.15"
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#override-the-entrypoint-of-an-image
entrypoint: [""]
before_script:
- |
echo ${CI_REGISTRY_PASSWORD} | \
skopeo login \
--username "$CI_REGISTRY_USER" \
--password-stdin \
"$CI_REGISTRY"
- |
echo ${DOCKER_HUB_PASSWORD} | \
skopeo login \
--username "$DOCKER_HUB_USERNAME" \
--password-stdin \
docker.io
script:
- |
skopeo copy --multi-arch all \
"docker://${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}" \
"docker://docker.io/mendersoftware/mender-artifact:${CI_COMMIT_REF_NAME}"

generate-qa-trigger:
image: python:alpine
stage: trigger_prep
Expand Down
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Keep golang version aligned with latest yocto release
FROM golang:1.17.13-bullseye as builder
RUN mkdir -p /go/src/github.com/mendersoftware/mender-artifact
WORKDIR /go/src/github.com/mendersoftware/mender-artifact
ADD ./ .
RUN make get-build-deps && \
make build && \
make install
ENTRYPOINT [ "/go/bin/mender-artifact" ]
FROM golang:1.22.4 as builder-deb
WORKDIR /build
COPY . .
RUN apt update && apt install -qy libssl-dev && \
make build

FROM debian:12.5-slim
COPY --from=builder-deb /build/mender-artifact /usr/bin/mender-artifact
RUN apt update && apt install -qy openssl
ENTRYPOINT ["/usr/bin/mender-artifact"]
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ VERSION = $(shell git describe --tags --dirty --exact-match 2>/dev/null || git r
GO_LDFLAGS = \
-ldflags "-X github.com/mendersoftware/mender-artifact/cli.Version=$(VERSION)"

BUILDFLAGS ?= -trimpath
ifeq ($(V),1)
BUILDV = -v
BUILDFLAGS += -v
endif

TAGS ?=
Expand All @@ -36,7 +37,7 @@ ifneq ($(GOOS),linux)
endif

build:
$(GO) build $(GO_LDFLAGS) $(BUILDV) -tags '$(TAGS)'
$(GO) build $(GO_LDFLAGS) $(BUILDFLAGS) -tags '$(TAGS)'

PLATFORMS := darwin linux windows

Expand Down Expand Up @@ -68,13 +69,13 @@ build-natives: build-native-linux build-native-mac build-native-windows
build-contained:
rm -f mender-artifact && \
image_id=$$(docker build -f Dockerfile -q .) && \
docker run --rm --entrypoint "/bin/sh" -v $(shell pwd):/binary $$image_id -c "cp /go/bin/mender-artifact /binary" && \
docker run --rm --entrypoint "/bin/sh" -v $(shell pwd):/binary $$image_id -c "cp /usr/bin/mender-artifact /binary" && \
docker image rm $$image_id

build-natives-contained:
rm -f mender-artifact-darwin mender-artifact-linux mender-artifact-windows.exe && \
image_id=$$(docker build -f Dockerfile.binaries -q .) && \
docker run --rm --entrypoint "/bin/sh" -v $(shell pwd):/binary $$image_id -c "cp /go/bin/mender-artifact* /binary" && \
docker run --rm --entrypoint "/bin/sh" -v $(shell pwd):/binary $$image_id -c "cp /usr/bin/mender-artifact* /binary" && \
docker image rm $$image_id

install:
Expand Down