Skip to content

Commit

Permalink
Add Docker support to improve reproducibility
Browse files Browse the repository at this point in the history
Signed-off-by: Benoit Donneaux <[email protected]>
  • Loading branch information
btlogy committed Jun 3, 2024
1 parent d004494 commit 3761ce9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.gocache
accessor/mock_gitea
accessor/mock_trac
mock_markdown
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,16 @@ Missing dependencies can be fetched using:
```lang-none
make deps
```

## Docker

In order to improve the reproducibility, one can leverage Docker:

```
docker compose build
docker compose run --rm go-shell
go version
...
make
...
```
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Docker compose file to provide a reproducable Go environment
version: '3'
services:
go-shell:
build:
context: docker/go
dockerfile: Dockerfile
args:
user: appuser
group: appgroup
uid: "${_UID:-1000}"
gid: "${_GID:-1000}"
environment:
- GOCACHE=/var/lib/appdata/.gocache
volumes:
- .:/var/lib/appdata
working_dir: /var/lib/appdata
stdin_open: true
tty: true
hostname: go-shell.local
container_name: go-shell.local
network_mode: "bridge"
# Prevents container to hang the host
# Requires `... --compatibility run ...`
deploy:
resources:
limits:
cpus: '1.5'
memory: 512M
34 changes: 34 additions & 0 deletions docker/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Start from the official Go image based on Alpine
FROM golang:1.19.3-alpine

LABEL Description="Trac2Gitea migration tool"

RUN apk --no-cache add gcc git libc-dev make

# Parameters for default user:group
ARG uid=1000
ARG user=appuser
ARG gid=1000
ARG group=appgroup

# Add user and group for build and runtime
RUN id ${user} > /dev/null 2>&1 || \
{ addgroup -g "${gid}" "${group}" && adduser -D -h /home/${user} -s /bin/bash -G "${group}" -u "${uid}" "${user}"; }

# Prepare directories
RUN DIRS="/src /app" && \
mkdir -p ${DIRS} && \
chown -R ${user}:${group} $DIRS

# Switch to non-root user
USER ${user}

# Install mockgen
#RUN go install go.uber.org/mock/[email protected]
#RUN ln -s /go /home/${user}/go

# Install pinned dependencies
#COPY go.mod go.sum /src
#WORKDIR /src
#RUN go mod download && \
# go mod verify

0 comments on commit 3761ce9

Please sign in to comment.