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

Build docker image #180

Merged
merged 10 commits into from
Sep 29, 2023
Merged

Build docker image #180

merged 10 commits into from
Sep 29, 2023

Conversation

thbkrkr
Copy link
Contributor

@thbkrkr thbkrkr commented Aug 4, 2023

This updates the Buildkite pipeline to release a container image that contains the multiple eck-diagnostics tool binaries.

The container image is built and pushed using drivah. The tag is defined using BUILDKITE_TAG if set else BUILDKITE_COMMIT:0:8. The tag is used to set the buildVersion in the tool.

Release when a git tag exists:

# build
> BUILDKITE_TAG=0.0.1 BUILDKITE_COMMIT=azertyuiopqsdfghjk make build-image
drivah build .
Using Docker container engine.
Scanning /Users/krkr/dev/src/github.com/elastic/eck-diagnostics...
Found 1 valid image definitions.
Building build with Docker...
Built docker.elastic.co/eck/diagnostics:0.0.1

# test
> d run --rm docker.elastic.co/eck/diagnostics:0.0.1 get | sh
eck-diagnostics-darwin-arm64 binary copied in local ✅

./eck-diagnostics -v
eck-diagnostics version 0.0.1

Else:

# build
> BUILDKITE_COMMIT=azertyuiopqsdfghjk make build-image
drivah build .
Using Docker container engine.
Scanning /Users/krkr/dev/src/github.com/elastic/eck-diagnostics...
Found 1 valid image definitions.
Building build with Docker...
Built docker.elastic.co/eck/diagnostics:azertyui

# test
> d run --rm docker.elastic.co/eck/diagnostics:azertyui get | sh
eck-diagnostics-darwin-arm64 binary copied in local ✅

./eck-diagnostics -v
eck-diagnostics version azertyui-SNAPSHOT

Two scripts entrypoint.sh and get.sh are used in the image to make it easier to understand how to extract binaries.

Flow in CI: drivah.toml.sh -> Dockerfile -> make build-binary.
Flow in dev: make build-image -> drivah.toml.sh -> Dockerfile -> make build-binary.

Testing:

> IMAGE_NAME=docker.elastic.co/eck-dev/diagnostics make build-image
drivah build .
Using Docker container engine.
Scanning /Users/krkr/dev/src/github.com/elastic/eck-diagnostics...
Found 1 valid image definitions.
Building build with Docker...
Built docker.elastic.co/eck-dev/diagnostics:cdf855f9

Message displayed when the image is called without argument:

> docker run --rm docker.elastic.co/eck-dev/diagnostics:cdf855f9

Copy the eck-diagnostics binary in the current directory from the container image using:

  docker run --rm docker.elastic.co/eck-dev/diagnostics:cdf855f9 get | sh

First call without | sh to check the content of the script:

> docker run --rm docker.elastic.co/eck-dev/diagnostics:cdf855f9 get
#!/bin/sh
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License 2.0;
# you may not use this file except in compliance with the Elastic License 2.0.
#

# Script to copy the eck-diagnostics binary  in the current directory from the container image.
# It is intended to be displayed on stdout and piped into sh.

set -eu

os=$(uname | tr '[:upper:]' '[:lower:]')
arch=$(uname -m | sed -e "s|x86_|amd|" -e "s|aarch|arm|")

docker run --rm -v $(pwd):/tmp --entrypoint cp "docker.elastic.co/eck-dev/diagnostics:cdf855f9" \
    -f "/artefacts/eck-diagnostics-${os}-${arch}" /tmp/eck-diagnostics

echo "eck-diagnostics-${os}-${arch} binary copied in local ✅"
echo
echo "./eck-diagnostics -v"
./eck-diagnostics -v

Let's copy the binary:

> docker run --rm docker.elastic.co/eck-dev/diagnostics:cdf855f9 get | sh
eck-diagnostics-darwin-arm64 binary copied in local ✅

./eck-diagnostics -v
eck-diagnostics version cdf855f9-SNAPSHOT

@thbkrkr thbkrkr added the enhancement New feature or request label Aug 4, 2023
@thbkrkr thbkrkr force-pushed the build-docker-image branch 5 times, most recently from 6030138 to a45f610 Compare September 22, 2023 08:08
@thbkrkr thbkrkr force-pushed the build-docker-image branch 2 times, most recently from cdf855f to c2299fd Compare September 22, 2023 08:51
@thbkrkr thbkrkr marked this pull request as ready for review September 22, 2023 09:06
Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

LGTM, tested on macOS. Awesome shell script wizardry 🪄

.buildkite/pipeline.yml Show resolved Hide resolved
@thbkrkr thbkrkr merged commit 7b661d5 into main Sep 29, 2023
3 checks passed
@thbkrkr thbkrkr deleted the build-docker-image branch November 8, 2023 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants