Skip to content

Commit 412d68c

Browse files
authored
Merge pull request #20 from civitatis/main
Dockerfile, additional scripts and minor improvements
2 parents e878fb4 + 2e3f5af commit 412d68c

File tree

12 files changed

+283
-31
lines changed

12 files changed

+283
-31
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dockerfile
2+
3+
CHANGELOG.md
4+
README.md
5+
LICENSE

.github/workflows/build-and-test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
jobs:
1010

1111
build:
12+
strategy:
13+
matrix:
14+
go-version: [ '1.21', '1.24' ]
15+
1216
runs-on: ubuntu-latest
1317
steps:
1418
- name: Install RabbitMQ
@@ -19,7 +23,7 @@ jobs:
1923
- name: Set up Go
2024
uses: actions/setup-go@v5
2125
with:
22-
go-version: '1.21'
26+
go-version: ${{ matrix.go-version }}
2327

2428
- name: Build
2529
run: go build -v ./...
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: build-container
2+
3+
on:
4+
push:
5+
ignore_branches: [ no_test ]
6+
pull_request:
7+
ignore_branches: [ no_test ]
8+
9+
jobs:
10+
11+
build_container_scratch:
12+
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Run build_container to generate scratch image
18+
run: scripts/build_container -g scratch -e BASE_IMAGE=scratch
19+
20+
build_container_params:
21+
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Run build_container to generate and image using kaniko
27+
run: scripts/build_container --tag kaniko --builder kaniko -t debug -e UID=1234 -e GID=5678
28+
29+
- name: Load rabbitmq-dump-queue:kaniko image
30+
run: docker load -i image.tar
31+
32+
- name: Test container ids
33+
run: docker run --rm --entrypoint= rabbitmq-dump-queue:kaniko /bin/id | grep --color=always '1234' | grep --color=always '5678'
34+
35+
build_container_test:
36+
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Run scripts/test
42+
run: scripts/test

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
/bin
22
/release
33
/rabbitmq-dump-queue
4+
5+
# exclude data dir
6+
/data
7+
# kaniko build tar
8+
image.tar

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Upcoming
44

5+
## v0.7.2 (2025-03-11)
6+
7+
* Update the RabbitMQ library to v1.10.0.
8+
* Update Go to 1.24.
9+
* Modify main.go to return help when no queue is provided
10+
* Add Dockerfile and .dockerignore [@drodbar](https://github.com/drodbar).
11+
* Add build_container and test scripts [@drodbar](https://github.com/drodbar).
12+
13+
514
## v0.7.1 (2024-01-26)
615

716
* Update the RabbitMQ library to v1.9.0.

Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ARG BASE_IMAGE=gcr.io/distroless/static
2+
3+
# build stage
4+
FROM golang:alpine AS build
5+
6+
COPY go* main* .
7+
8+
RUN apk add --no-cache git
9+
10+
RUN CGO_ENABLED=0 go build -o rabbitmq-dump-queue .
11+
12+
13+
# test stage
14+
FROM build AS test
15+
16+
ENV GOPATH=''
17+
ENTRYPOINT [ "go", "test" ]
18+
19+
20+
# production stage
21+
FROM ${BASE_IMAGE} AS production
22+
ARG UID=65532
23+
ARG GID=65532
24+
25+
# make latest alpine certs available
26+
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
27+
28+
USER ${UID}:${GID}
29+
30+
# copy app binary
31+
COPY --from=build /go/rabbitmq-dump-queue /usr/local/bin/
32+
33+
ENTRYPOINT [ "rabbitmq-dump-queue" ]
34+
35+
# volume dir to output data
36+
VOLUME /data
37+
WORKDIR /data
38+
39+
40+
# degug stage
41+
FROM busybox:stable-uclibc AS busybox
42+
FROM production AS debug
43+
44+
COPY --from=busybox /bin/id /bin/sh /bin/busybox /bin/
45+
46+
47+
# default stage: production
48+
FROM production

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# rabbitmq-dump-queue
2-
32
Dump messages from a RabbitMQ queue to files, without affecting the queue.
43

54
[![build-and-test](https://github.com/dubek/rabbitmq-dump-queue/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/dubek/rabbitmq-dump-queue/actions/workflows/build-and-test.yml)
@@ -17,12 +16,34 @@ If you have [Go](https://golang.org/doc/install) installed, you can install
1716
rabbitmq-dump-queue from source by running:
1817

1918
```
20-
go get github.com/dubek/rabbitmq-dump-queue
19+
go install github.com/dubek/rabbitmq-dump-queue
2120
```
2221

2322
The `rabbitmq-dump-queue` executable will be created in the `$GOPATH/bin`
2423
directory.
2524

25+
### Compile in docker
26+
27+
If you want to use the application within a root-less container use `scripts/build_container`
28+
29+
``` bash
30+
$ scripts/build_container -h
31+
Usage: build_container [OPTIONS]
32+
33+
Options:
34+
-b, --builder <builder> Specify the builder (docker or kaniko).
35+
-t, --target <target> Specify the target (build, test, debug or production).
36+
Default: production.
37+
-g, --tag <tag> Specify the tag.
38+
Default: latest for production target or <target>.
39+
-p, --dry-run Print only mode.
40+
-h, --help Display this help message.
41+
42+
Examples:
43+
build_container -b docker -t my-image --tag latest
44+
build_container --builder kaniko --target debug
45+
46+
```
2647

2748
## Usage
2849

@@ -123,6 +144,9 @@ To stop the RabbitMQ server container, run:
123144
docker stop test-rabbitmq
124145
docker rm test-rabbitmq
125146

147+
Testing with `docker` can simpify the task, simply run:
148+
149+
bash scripts/test
126150

127151
## Contributing
128152

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/dubek/rabbitmq-dump-queue
22

3-
go 1.21
3+
go 1.24
44

5-
require github.com/rabbitmq/amqp091-go v1.9.0
5+
require github.com/rabbitmq/amqp091-go v1.10.0

go.sum

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4-
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
5-
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
6-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
7-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
8-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
9-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11-
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
12-
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
13-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
14-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
15-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
16-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
17-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
18-
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
19-
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
20-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
21-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
22-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
23-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
24-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
25-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1+
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
2+
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
3+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
4+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func dial(amqpURI string) (*amqp091.Connection, error) {
5252

5353
func dumpMessagesFromQueue(amqpURI string, queueName string, maxMessages uint, outputDir string) error {
5454
if queueName == "" {
55-
return fmt.Errorf("Must supply queue name")
55+
error := fmt.Errorf("Must supply queue name")
56+
flag.Usage()
57+
return error
5658
}
5759

5860
conn, err := dial(amqpURI)

0 commit comments

Comments
 (0)