-
Notifications
You must be signed in to change notification settings - Fork 46
Dockerfile, additional scripts and minor improvements #20
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
Open
drodbar
wants to merge
11
commits into
dubek:main
Choose a base branch
from
civitatis:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d25b74f
feat: Upgrade amqp lib and golang versions
drodbar 5220cdf
fix: github CICD test execution
drodbar 76c1037
chore: github actions to test go 1.21 and 1.24
drodbar 562599b
chore: remove README version
drodbar 233a369
chore: go fmt main.go
drodbar b33bf12
chore: default base image changed to distroless; feat: allow build-ar…
drodbar 824831f
chore: remove ldflags build switch
drodbar feded15
chore: change comment location + credit attribution
drodbar fec2c78
chore: remove wait-for-it.sh script in favour of a simpler nc test fo…
drodbar 4258cd5
feat: add github action to test build_container and run containerized…
drodbar 2e3f5af
chore: parametrize RABBITMQ_START_TIMEOUT in scripts/test
drodbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Dockerfile | ||
|
||
CHANGELOG.md | ||
README.md | ||
LICENSE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: build-container | ||
|
||
on: | ||
push: | ||
ignore_branches: [ no_test ] | ||
pull_request: | ||
ignore_branches: [ no_test ] | ||
|
||
jobs: | ||
|
||
build_container_scratch: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Run build_container to generate scratch image | ||
run: scripts/build_container -g scratch -e BASE_IMAGE=scratch | ||
|
||
build_container_params: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Run build_container to generate and image using kaniko | ||
run: scripts/build_container --tag kaniko --builder kaniko -t debug -e UID=1234 -e GID=5678 | ||
|
||
- name: Load rabbitmq-dump-queue:kaniko image | ||
run: docker load -i image.tar | ||
|
||
- name: Test container ids | ||
run: docker run --rm --entrypoint= rabbitmq-dump-queue:kaniko /bin/id | grep --color=always '1234' | grep --color=always '5678' | ||
|
||
build_container_test: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Run scripts/test | ||
run: scripts/test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
/bin | ||
/release | ||
/rabbitmq-dump-queue | ||
|
||
# exclude data dir | ||
/data | ||
# kaniko build tar | ||
image.tar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
ARG BASE_IMAGE=gcr.io/distroless/static | ||
|
||
# build stage | ||
FROM golang:alpine AS build | ||
|
||
COPY go* main* . | ||
|
||
RUN apk add --no-cache git | ||
|
||
RUN CGO_ENABLED=0 go build -o rabbitmq-dump-queue . | ||
|
||
|
||
# test stage | ||
FROM build AS test | ||
|
||
ENV GOPATH='' | ||
ENTRYPOINT [ "go", "test" ] | ||
|
||
|
||
# production stage | ||
FROM ${BASE_IMAGE} AS production | ||
ARG UID=65532 | ||
ARG GID=65532 | ||
|
||
# make latest alpine certs available | ||
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
USER ${UID}:${GID} | ||
|
||
# copy app binary | ||
COPY --from=build /go/rabbitmq-dump-queue /usr/local/bin/ | ||
|
||
ENTRYPOINT [ "rabbitmq-dump-queue" ] | ||
|
||
# volume dir to output data | ||
VOLUME /data | ||
WORKDIR /data | ||
|
||
|
||
# degug stage | ||
FROM busybox:stable-uclibc AS busybox | ||
FROM production AS debug | ||
|
||
COPY --from=busybox /bin/id /bin/sh /bin/busybox /bin/ | ||
|
||
|
||
# default stage: production | ||
FROM production |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/dubek/rabbitmq-dump-queue | ||
|
||
go 1.21 | ||
go 1.24 | ||
|
||
require github.com/rabbitmq/amqp091-go v1.9.0 | ||
require github.com/rabbitmq/amqp091-go v1.10.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,4 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo= | ||
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= | ||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= | ||
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw= | ||
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o= | ||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= | ||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/bash | ||
|
||
set -e -o pipefail | ||
|
||
usage() { | ||
cat << USAGE >&2 | ||
Usage: $0 [OPTIONS] | ||
|
||
Options: | ||
-b, --builder <builder> Specify the builder (docker or kaniko). | ||
-e, --extra-args <arg=value> Specify additional build-args. | ||
-t, --target <target> Specify the target (build, test, debug or production). | ||
Default: production. | ||
-g, --tag <tag> Specify the tag. | ||
Default: latest for production target or <target>. | ||
-p, --dry-run Print only mode. | ||
-h, --help Display this help message. | ||
|
||
Examples: | ||
$0 -b docker -t test --tag latest | ||
$0 --builder kaniko --target debug | ||
$0 -g local -e UID=\$UID -e GID=\$GID -e BASE_IMAGE=scratch | ||
|
||
USAGE | ||
exit 1 | ||
} | ||
|
||
main() { | ||
parse_args "$@" | ||
set_default | ||
build_image | ||
} | ||
|
||
build_with_docker() { | ||
${DRY_RUN} docker buildx build \ | ||
-t "${IMAGE_NAME}:${TAG}" \ | ||
"${BUILD_ARGS[@]}" \ | ||
--target="${TARGET}" . | ||
} | ||
|
||
build_with_kaniko() { | ||
KANIKO_IMG="gcr.io/kaniko-project/executor:latest" | ||
${DRY_RUN} docker run -w /build \ | ||
-v "$PWD":/build \ | ||
--rm \ | ||
"${KANIKO_IMG}" \ | ||
"${BUILD_ARGS[@]}" \ | ||
-d "${IMAGE_NAME}:${TAG}" \ | ||
--target "${TARGET}" \ | ||
--context . \ | ||
--no-push \ | ||
--tar-path=/build/image.tar | ||
} | ||
|
||
parse_args() { | ||
set -- "$@" "${EOL:=$(printf '\1\3\3\7')}" # end-of-list marker | ||
while [ "$1" != "$EOL" ]; do | ||
opt="$1"; shift | ||
case $opt in | ||
--builder|-b) BUILDER="$1"; shift; ;; | ||
--extra-args|-e) BUILD_ARGS+=( --build-arg "$1" ); shift; ;; | ||
--target|-t) TARGET="$1"; shift; ;; | ||
--tag|-g) TAG="$1"; shift; ;; | ||
--help|-h) usage; ;; | ||
--dry-run|-p) DRY_RUN='echo'; ;; | ||
*) printf "[ERROR] Unknwon arg [%s]\n" "$opt" >&2; usage; ;; | ||
esac | ||
done; shift | ||
} | ||
|
||
set_default() { | ||
: "${BUILDER:="docker"}" | ||
: "${TARGET:="production"}" | ||
: "${IMAGE_NAME:="rabbitmq-dump-queue"}" | ||
case "$TARGET" in | ||
production) DEFAULT_TAG="latest"; ;; | ||
*) DEFAULT_TAG="${TARGET}" | ||
esac | ||
: "${TAG:="$DEFAULT_TAG"}" | ||
} | ||
|
||
build_image() { | ||
case $BUILDER in | ||
kaniko) build_with_kaniko; ;; | ||
docker) build_with_docker; ;; | ||
*) echo "[ERROR] Unsupported builder [${BUILDER}]" | ||
esac | ||
} | ||
|
||
main "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
DIRNAME="$(dirname "$(readlink -f "$0")")" | ||
|
||
: "${RABBITMQ_START_TIMEOUT:=30}" | ||
|
||
trap rm_containters EXIT | ||
trap errors_found ERR | ||
|
||
info_msg() { printf "[\033[34mINFO\033[0m] %b\n" "$*"; } | ||
error_msg() { printf "[\033[31mERROR\033[0m] %b\n" "$*"; } | ||
|
||
rm_containters() { | ||
docker kill rdq-test >/dev/null 2>&1 || true | ||
docker kill rdq-busybox >/dev/null 2>&1 || true | ||
docker kill rdq-rabbitmq >/dev/null 2>&1 || true | ||
} | ||
|
||
errors_found() { | ||
error_msg "$0 didn't finish correctly: rc [\033[31m$?\033[0m]" | ||
} | ||
|
||
info_msg "Build rabbitmq-dump-queue test image" | ||
"${DIRNAME}/build_container" --target test >/dev/null 2>&1 | ||
|
||
info_msg "Start rabbitmq container" | ||
docker run --network=host --rm -q \ | ||
--detach \ | ||
--name rdq-rabbitmq \ | ||
rabbitmq:4-management >/dev/null | ||
|
||
info_msg "Wait for rabbitmq listener up to [\033[32m${RABBITMQ_START_TIMEOUT}s\033[0m]" | ||
docker run --network=host --rm -q \ | ||
--name rdq-busybox \ | ||
-e N="$RABBITMQ_START_TIMEOUT" \ | ||
busybox \ | ||
sh -c 'while [ $N -ge 0 ]; do nc -z localhost 5672 >/dev/null && exit 0; sleep 1; N=$((N - 1)); done; exit 1' | ||
|
||
info_msg "Run tests" | ||
docker run --network=host --rm \ | ||
--name rdq-test\ | ||
rabbitmq-dump-queue:test |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.