Skip to content

Commit

Permalink
Update docker containers and use docker buildx to make multiplatform …
Browse files Browse the repository at this point in the history
…containers.
  • Loading branch information
quintush committed Jul 17, 2024
1 parent 74eb056 commit 656b272
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
18 changes: 10 additions & 8 deletions AlpineTest.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
FROM --platform=$BUILDPLATFORM alpine:3

# variable "HELM_VERSION" and "PLUGIN_VERSION" must be passed as docker environment variables during the image build
# docker build --load --no-cache --platform linux/amd64 --build-arg HELM_VERSION=3.13.0 -t alpine/helm-unittest:test -f AlpineTest.Dockerfile .
# docker buildx build --load --no-cache --platform linux/amd64 --build-arg HELM_VERSION=3.13.0 -t alpine/helm-unittest:test -f AlpineTest.Dockerfile .

COPY plugin.yaml /helm-unittest/plugin.yaml
COPY install-binary.sh /helm-unittest/install-binary.sh
ADD plugin.yaml helm-unittest/plugin.yaml
ADD install-binary.sh helm-unittest/install-binary.sh
ADD untt helm-unittest/untt

ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG HELM_VERSION

#ENV SKIP_BIN_DOWNLOAD=1
ENV SKIP_BIN_INSTALL=1
ENV HELM_BASE_URL="https://get.helm.sh"
ENV HELM_TAR_FILE="helm-v${HELM_VERSION}-${TARGETOS}-${TARGETARCH}.tar.gz"
ENV PLUGIN_URL="helm-unittest"
# Install the plugin for all users
ENV HELM_DATA_HOME=/usr/local/share/helm

RUN apk add --update --no-cache curl ca-certificates git && \
RUN apk add --update --no-cache curl ca-certificates git libc6-compat && \
curl -L ${HELM_BASE_URL}/${HELM_TAR_FILE} |tar xvz && \
mv ${TARGETOS}-${TARGETARCH}/helm /usr/bin/helm && \
chmod +x /usr/bin/helm && \
Expand All @@ -27,13 +28,14 @@ RUN apk add --update --no-cache curl ca-certificates git && \
apk del curl git && \
rm -f /var/cache/apk/* ;

RUN addgroup -S helmgroup && \
adduser -S helmuser -G helmgroup
RUN addgroup -g 1000 -S helmgroup && \
adduser -u 1000 -S helmuser -G helmgroup

USER helmuser

WORKDIR /apps
VOLUME [ "/apps" ]

VOLUME ["/apps"]

ENTRYPOINT ["helm", "unittest"]
CMD ["--help"]
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ RUN apk add --update --no-cache curl ca-certificates git bash && \
apk del curl git bash && \
rm -f /var/cache/apk/*

RUN addgroup -S helmgroup && \
adduser -S helmuser -G helmgroup
RUN addgroup -g 1000 -S helmgroup && \
adduser -u 1000 -S helmuser -G helmgroup

USER helmuser

Expand Down
15 changes: 8 additions & 7 deletions Fedora.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
FROM --platform=$BUILDPLATFORM fedora:40

# variable "HELM_VERSION" must be passed as docker environment variables during the image build
# docker build --no-cache --platform linux/amd64 --build-arg HELM_VERSION=3.13.0 -t fedora/helm-unittest:test -f Fedora.Dockerfile .
# docker buildx build --load --no-cache --platform linux/amd64 --build-arg HELM_VERSION=3.13.0 -t fedora/helm-unittest:test -f Fedora.Dockerfile .

ADD ./plugin.yaml ~/plugin.yaml
ADD ./plugin-dbg.yaml ~/plugin-dbg.yaml
ADD ./install-binary.sh ~/install-binary.sh
ADD plugin.yaml helm-unittest/plugin.yaml
ADD install-binary.sh helm-unittest/install-binary.sh
ADD untt helm-unittest/untt

ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG HELM_VERSION

ENV SKIP_BIN_INSTALL=1
ENV HELM_BASE_URL="https://get.helm.sh"
ENV HELM_TAR_FILE="helm-v${HELM_VERSION}-${TARGETOS}-${TARGETARCH}.tar.gz"
ENV PLUGIN_URL="~"
ENV PLUGIN_URL="helm-unittest"
# Install the plugin for all users
ENV HELM_DATA_HOME=/usr/local/share/helm

Expand All @@ -27,8 +28,8 @@ RUN yum install -y git && \
yum remove -y git && \
rm -rf /var/cache/yum/* ;

RUN groupadd -r helmgroup \
&& useradd -r helmuser -g helmgroup
RUN groupadd -g 1000 -r helmgroup \
&& useradd -u 1000 -r helmuser -g helmgroup

USER helmuser

Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# borrowed from https://github.com/technosophos/helm-template

GO ?= go
HELM_3_PLUGINS := $(shell bash -c 'eval $$(helm env); echo $$HELM_PLUGINS')
HELM_PLUGIN_DIR := $(HELM_3_PLUGINS)/helm-unittest
HELM_VERSION := 3.14.0
Expand All @@ -14,7 +13,6 @@ TEST_NAMES ?=basic \
failing-template \
full-snapshot \
global-double-setting \
invalidbasic \
nested_glob \
with-document-select \
with-files \
Expand Down Expand Up @@ -83,18 +81,18 @@ dockerdist:

.PHONY: go-dependency
dependency: ## Dependency maintanance
@$(GO) get -u ./...
@$(GO) mod tidy
go get -u ./...
go mod tidy

.PHONY: dockerimage
dockerimage: ## Build docker image
docker buildx build --no-cache --load --platform linux/amd64 --build-arg HELM_VERSION=$(HELM_VERSION) -t $(DOCKER):$(VERSION) -f AlpineTest.Dockerfile .
docker buildx build --load --no-cache --platform linux/amd64 --build-arg HELM_VERSION=$(HELM_VERSION) -t $(DOCKER):$(VERSION) -f Fedora.Dockerfile .

.PHONY: test-docker
test-docker: dockerimage ## Execute 'helm unittests' in container
@for f in $(TEST_NAMES); do \
echo "running helm unit tests in folder '$${f}'"; \
docker run \
-v $(PROJECT_DIR)/test/data/v3/$${f}:/apps/:Z \
-v $(PROJECT_DIR)/test/data/v3/$${f}:/apps \
-it --rm $(DOCKER):$(VERSION) -f tests/*.yaml .;\
done
2 changes: 1 addition & 1 deletion pkg/unittest/snapshot/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ensureDir(path string) error {
info, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return os.Mkdir(path, os.ModePerm)
return os.Mkdir(path, 0755)
}
return err
}
Expand Down

0 comments on commit 656b272

Please sign in to comment.