Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [VIO-3019] Update the Dockerfiles #119

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
#
# Builder Image
#
FROM docker.io/vaporio/golang:1.16 as builder
# FROM docker.io/library/golang:1.16 as builder
FROM docker.io/library/debian:stable-slim as builder

RUN apt-get update && apt-get install -y ca-certificates

RUN useradd -M vaporio

RUN mkdir -p /etc/synse/plugin/config \
&& mkdir -p /etc/synse/plugin/config \
&& chown -R vaporio /etc/synse

#
# Final Image
#
FROM docker.io/vaporio/scratch-ish:1.0.0
FROM scratch

LABEL org.label-schema.schema-version="1.0" \
org.label-schema.name="vaporio/emulator-plugin" \
org.label-schema.vcs-url="https://github.com/vapor-ware/synse-emulator-plugin" \
org.label-schema.vendor="Vapor IO"

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/passwd /etc/passwd

# Build the device configurations directly into the image. This is not
# generally advised, but is acceptable here since the plugin is merely
# an emulator and its config is not tied to anything real.
COPY config/device /etc/synse/plugin/config/device
COPY config.yml /etc/synse/plugin/config/config.yml
COPY --chown=vaporio config/device /etc/synse/plugin/config/device
COPY --chown=vaporio config.yml /etc/synse/plugin/config/config.yml

# Copy the executable.
COPY synse-emulator-plugin ./plugin
COPY --chown=vaporio synse-emulator-plugin /plugin

EXPOSE 5001
ENTRYPOINT ["./plugin"]

USER vaporio
ENTRYPOINT ["/plugin"]
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ deploy: ## Run a local deployment of the plugin with Synse Server

.PHONY: docker
docker: ## Build the production docker image locally
docker build -f Dockerfile \
--label "org.label-schema.build-date=${BUILD_DATE}" \
--label "org.label-schema.vcs-ref=${GIT_COMMIT}" \
--label "org.label-schema.version=${PLUGIN_VERSION}" \
-t ${IMAGE_NAME}:latest . || exit
env GOLANG_VERSION=${GOLANG_VERSION} goreleaser release --snapshot --clean

.PHONY: docker-dev
docker-dev: ## Build the development docker image locally
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,21 @@ The plugin can be run in debug mode for additional logging. This is done by:
docker run -e PLUGIN_DEBUG=true vaporio/emulator-plugin
```

### Building

To build the production image locally, you'll first need to [install the goreleaser binary](https://goreleaser.com/install/).

```
make docker
```

This will run `goreleaser` to build a local image tagged as the current release, i.e., `docker.io/vaporio/emulator-plugin:3.4.1`.

### Developing

A [development/debug Dockerfile](Dockerfile.dev) is provided in the project repository to enable
building image which may be useful when developing or debugging a plugin. Unlike the slim `scratch`-based
production image, the development image uses an ubuntu base, bringing with it all the standard command line
production image, the development image uses a Debian base, bringing with it all the standard command line
tools one would expect. To build a development image:

```
Expand Down
61 changes: 50 additions & 11 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,61 @@
# Development images contain additional tooling that makes it easier
# to exec into a contain and dig into whatever may be going on inside.
#
#
# Builder Image
#
FROM docker.io/library/golang:1.16 as builder

RUN apt-get update && apt-get install -y ca-certificates

RUN useradd -M vaporio

WORKDIR /app

# Download dependencies
COPY go.* ./
RUN go mod download

# Copy the project into the builder
COPY . ./

# Disable dynamic linking. The binary won't work on scratch otherwise
ENV CGO_ENABLED=0

FROM vaporio/golang:1.16
# Build the binary.
RUN make build-linux

WORKDIR /synse

RUN mkdir -p /etc/synse/plugin/config \
&& mkdir -p /etc/synse/plugin/config \
&& chown -R vaporio /etc/synse \
&& chown -R vaporio /app

#
# Final Image
#
FROM docker.io/library/debian:stable-slim

LABEL org.label-schema.schema-version="1.0" \
org.label-schema.name="vaporio/emulator-plugin" \
org.label-schema.vcs-url="https://github.com/vapor-ware/synse-emulator-plugin" \
org.label-schema.vendor="Vapor IO"

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/passwd /etc/passwd

# Build the device configurations directly into the image. This is not
# generally advised, but is acceptable here since the plugin is merely
# an emulator and its config is not tied to anything real. These config
# defaults may be overridden at run time.
COPY config/device /etc/synse/plugin/config/device
COPY config.yml /etc/synse/plugin/config/config.yml
# an emulator and its config is not tied to anything real.
COPY --chown=vaporio config/device /etc/synse/plugin/config/device
COPY --chown=vaporio config.yml /etc/synse/plugin/config/config.yml

# Copy the executable.
COPY --chown=vaporio --from=builder /app/synse-emulator-plugin /app/plugin

# Copy the executable and README information. The executable should be
# built prior to the image build (see Makefile).
COPY synse-emulator-plugin ./plugin
COPY README.md .

EXPOSE 5001
ENTRYPOINT ["./plugin"]

USER vaporio
ENTRYPOINT ["/app/plugin"]