Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
This allows using xk6 via Docker, without having to setup a local Go
environment or install xk6.

Unfortunately, file permissions with mounted volumes are still an
issue[1], without a simple, native fix. fixuid[2] seems to be the modern
solution to this, and works well from my tests.

Part of #8

[1]: moby/moby#7198

[2]: https://github.com/boxboat/fixuid
  • Loading branch information
Ivan Mirić committed Feb 27, 2023
1 parent 2edb8de commit 9be35b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG GO_VERSION=1.20.1
ARG VARIANT=bullseye
FROM golang:${GO_VERSION}-${VARIANT} as builder

WORKDIR /build

COPY . .

ARG GOFLAGS="-ldflags=-w -ldflags=-s"
RUN CGO_ENABLED=0 go build -o xk6 -trimpath ./cmd/xk6/main.go


FROM golang:${GO_VERSION}-${VARIANT}

RUN addgroup --gid 1000 xk6 && \
adduser --uid 1000 --ingroup xk6 --home /home/xk6 --shell /bin/sh --disabled-password --gecos "" xk6

ARG FIXUID_VERSION=0.5.1
RUN USER=xk6 && \
GROUP=xk6 && \
curl -fSsL https://github.com/boxboat/fixuid/releases/download/v${FIXUID_VERSION}/fixuid-${FIXUID_VERSION}-linux-amd64.tar.gz | tar -C /usr/local/bin -xzf - && \
chown root:root /usr/local/bin/fixuid && \
chmod 4755 /usr/local/bin/fixuid && \
mkdir -p /etc/fixuid && \
printf "user: $USER\ngroup: $GROUP\n" > /etc/fixuid/config.yml

COPY --from=builder /build/xk6 /usr/local/bin/

COPY docker-entrypoint.sh /usr/local/bin/entrypoint.sh

WORKDIR /xk6
RUN chown xk6:xk6 /xk6
USER xk6

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
6 changes: 6 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e

eval "$(fixuid)"

exec /usr/local/bin/xk6 "$@"

0 comments on commit 9be35b4

Please sign in to comment.