Skip to content

Commit

Permalink
fix: default Dockerfile build to the runnable agent stage (#246)
Browse files Browse the repository at this point in the history
When called without a target, docker build produces an image based on
the final stage in a multi-stage Dockerfile. This rearranges our
Dockerfile so that the default is the runnable agent image and not the
final state of compiling and testing.

Co-authored-by: Jamie Danielson <jamieedanielson@gmail.com>
Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
  • Loading branch information
3 people committed Sep 27, 2023
1 parent 0cfc442 commit 2166886
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# uses docker multi-stage builds: https://docs.docker.com/build/building/multi-stage/
# base stage builds the agent binary for use in later stages
FROM golang:1.21 as base
RUN apt update -yq && apt install -yq make libpcap-dev
WORKDIR /src
Expand All @@ -6,10 +8,13 @@ RUN go mod download
COPY . .
RUN make build

FROM ubuntu:22.04 as build
# run tests with 'docker build --target test .'; skips the runnable image build
FROM base as test
RUN make test

# last unnamed stage is the default target for any image build
# this produces the runnable agent image
FROM ubuntu:22.04
RUN apt-get update -yq && apt-get install -yq ca-certificates libpcap-dev
COPY --from=base /src/hny-network-agent /bin/hny-network-agent
ENTRYPOINT [ "/bin/hny-network-agent" ]

FROM base as test
RUN make test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build:
.PHONY: docker-build
#: build the agent image
docker-build:
docker build --target build --tag $(IMG_NAME):$(IMG_TAG) .
docker build --tag $(IMG_NAME):$(IMG_TAG) .

.PHONY: test
#: run unit tests
Expand Down

0 comments on commit 2166886

Please sign in to comment.