I have one Dockerfile with two stages (dev, with necessary golang packages and a binary for testing) and prod (alpine linux, binary/scripts/configuration files only).
I’m trying to condense a Golang project down into a simple .drone.yml (tested on drone-cli 0.8.3 and 0.8.5) file that will do a few things:
- Builds both images and tags them
- Runs a test script
- Builds and/or runs a production container
The problem I’m facing is that when I do
drone exec --local
The DB and docker images build fine, but when I get to the test phase of the pipeline, the test script fails because the final binary can’t be found. I’ve confirmed in multiple ways that the binary does in fact exist, through running the container and ls’ing, etc.
This also goes for the godog binary in /go/bin, hence the go get commands in drome.yml
.drone.yml:
workspace:
base: /go
path: src/project
context: .
pipeline:
build:
image: docker
commands:
- docker build --tag project:latest --target project-dev --file ./docker/dev/Dockerfile.dev .
- docker build --tag project:latest --target project-prod --file ./docker/dev/Dockerfile.dev .
volumes:
- /var/run/docker.sock:/var/run/docker.sock
test:
image: project-dev:latest
pull: true
commands:
- go get github.com/DATA-DOG/godog/cmd/godog
- ./scripts/test.sh
Dockerfile.dev:
FROM golang:1.10 AS project-dev
RUN apt-get update
RUN apt-get install -y protobuf-compiler
COPY . /go/src/project
WORKDIR /go/src/project
RUN go get ./...
RUN go get github.com/DATA-DOG/godog/cmd/godog
RUN go get github.com/derekparker/delve/cmd/dlv
RUN go get github.com/golang/protobuf/protoc-gen-go
RUN ls -hal
RUN ./scripts/build.sh
RUN ls -hal
FROM alpine:latest AS project-prod
#Install bash so we can run actual scripts
RUN apk update
RUN apk add bash
EXPOSE 9876
RUN mkdir -p /project
WORKDIR /project
COPY --from=project-dev:latest /go/src/project/scripts/test.sh /project/scripts/
COPY --from=project-dev:latest /go/src/project/bin/project /project/bin/
COPY --from=project-dev:latest /go/src/project/etc/config.json /project/etc/
COPY --from=cmapi-dev:latest /go/src/project/docker/prod/prod-entrypoint.sh /project/prod-entrypoint.sh
ENTRYPOINT ["/bin/bash", "/project/prod-entrypoint.sh"]