forked from DominicBreuker/pspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.testing
37 lines (30 loc) · 1.19 KB
/
Dockerfile.testing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
FROM golang:1.12-stretch
RUN apt-get update && apt-get -y install cron python3 sudo procps
### Test and build ###
# copy source code
COPY main.go /go/src/github.com/dominicbreuker/pspy/main.go
COPY cmd /go/src/github.com/dominicbreuker/pspy/cmd
COPY internal /go/src/github.com/dominicbreuker/pspy/internal
COPY vendor /go/src/github.com/dominicbreuker/pspy/vendor
COPY .git /go/src/github.com/dominicbreuker/pspy/.git
# run tests
WORKDIR /go/src/github.com/dominicbreuker/pspy
RUN go test ./...
# build executable
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o bin/pspy main.go
### Prepare integration test ###
# install root cronjob
COPY docker/var/spool/cron/crontabs /var/spool/cron/crontabs
RUN chmod 600 /var/spool/cron/crontabs/root
COPY docker/root/scripts /root/scripts
# set up unpriviledged user
# allows passwordless sudo to start cron as root on startup
RUN useradd -ms /bin/bash myuser && \
adduser myuser sudo && \
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER myuser
RUN sudo chown -R myuser:myuser /go/*
# drop into bash shell
COPY docker/entrypoint-testing.sh /entrypoint.sh
RUN sudo chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]