Skip to content

Commit

Permalink
Merge pull request #1000 from flanksource/minimal-image
Browse files Browse the repository at this point in the history
feat: generate minimal and elevated base images
  • Loading branch information
BrendanGalloway authored May 23, 2023
2 parents 402617d + 59e79f6 commit 6364399
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
env:
CI: false
run: |
mkdir -p ui/build
touch ui/build/noop
make resources
git diff
changed_files=$(git status -s)
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ bin/
.env
.certs
.kube
build/
docs/cli/
.DS_Store
cover.out
Expand All @@ -18,4 +17,4 @@ chart/templates/crd.yaml
postgres-db/
ui/scripts/
Chart.lock
chart/charts/
chart/charts/
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ else
endif

# Image URL to use all building/pushing image targets
IMG_F ?= docker.io/flanksource/canary-checker-full:${VERSION_TAG}
IMG ?= docker.io/flanksource/canary-checker:${VERSION_TAG}

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
Expand Down Expand Up @@ -83,21 +84,26 @@ generate: .bin/controller-gen

# Build the docker image
docker:
docker build . -t ${IMG}
docker build . -f build/full/Dockerfile -t ${IMG_F}
docker build . -f build/minimal/Dockerfile -t ${IMG}

# Build the docker image
docker-dev: linux
docker build ./ -f ./Dockerfile.dev -t ${IMG}
docker build ./ -f build/dev/Dockerfile -t ${IMG}


docker-push-%:
docker build ./ -f ./Dockerfile.dev -t ${IMG}
docker build . -f build/full/Dockerfile -t ${IMG_F}
docker build . -f build/minimal/Dockerfile -t ${IMG}
docker tag $(IMG_F) $*/$(IMG_F)
docker tag $(IMG) $*/$(IMG)
docker push $*/$(IMG_F)
docker push $*/$(IMG)
kubectl set image deployment/$(NAME) $(NAME)=$*/$(IMG)
kubectl set image deployment/$(NAME) $(NAME)=$*/$(IMG_F)

# Push the docker image
docker-push:
docker push ${IMG_F}
docker push ${IMG}

.PHONY: compress
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions Dockerfile → build/full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ WORKDIR /app

ARG NAME
ARG VERSION
ENV IMAGE_TYPE=full
COPY go.mod /app/go.mod
COPY go.sum /app/go.sum
RUN go mod download
Expand Down
32 changes: 32 additions & 0 deletions build/minimal/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:1.20 AS builder
WORKDIR /app

ARG NAME
ARG VERSION
ENV IMAGE_TYPE=minimal
COPY go.mod /app/go.mod
COPY go.sum /app/go.sum
RUN go mod download
COPY ./ ./
RUN go version
RUN make build

FROM ubuntu
WORKDIR /app
RUN apt-get update && \
apt-get install -y curl unzip ca-certificates jq wget gnupg2 bzip2 --no-install-recommends && \
rm -Rf /var/lib/apt/lists/* && \
rm -Rf /usr/share/doc && rm -Rf /usr/share/man && \
apt-get clean

COPY --from=builder /app/.bin/canary-checker /app

RUN /app/canary-checker go-offline

RUN mkdir /opt/database
RUN groupadd --gid 1000 canary
RUN useradd canary --uid 1000 -g canary -m -d /var/lib/canary
RUN chown -R 1000:1000 /opt/database
USER canary:canary

ENTRYPOINT ["/app/canary-checker"]
7 changes: 7 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ app.kubernetes.io/name: {{ include "canary-checker.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
control-plane: canary-checker
{{- end }}

{{/*
Image Name
*/}}
{{- define "canary-checker.imageString" -}}
{{ .Values.image.repository }}{{- if eq (lower .Values.image.type) "full" }}-full{{- end }}:{{ .Values.image.tag }}
{{- end }}
2 changes: 1 addition & 1 deletion chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ spec:
capabilities:
add:
- CAP_NET_RAW
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
image: {{ include "canary-checker.imageString" . }}
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
env:
{{- if eq .Values.debug true }}
Expand Down
3 changes: 3 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ replicas: 1

image:
repository: docker.io/flanksource/canary-checker
## Options: minimal | full
## full image is larger and requires more permissions to run, but is required to execute 3rd party checks (jmeter, restic, k6 etc)
type: minimal
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"
Expand Down

0 comments on commit 6364399

Please sign in to comment.