-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and add test for getContainerImage (#191)
apparently this can be trickier than it seems
- Loading branch information
1 parent
5488f2d
commit 0d8c432
Showing
5 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
FROM golang:1.22-alpine3.19 as builder | ||
|
||
ARG TARGETARCH | ||
ARG TARGETOS | ||
ARG VERSION | ||
|
||
WORKDIR /workspace | ||
|
||
# Retrieve application dependencies. | ||
# This allows the container build to reuse cached dependencies. | ||
# Expecting to copy go.mod and if present go.sum. | ||
COPY go.* ./ | ||
RUN go mod download | ||
|
||
COPY cmd/harness ./cmd/harness | ||
COPY pkg ./pkg | ||
COPY internal ./internal | ||
COPY api ./api | ||
|
||
RUN CGO_ENABLED=0 \ | ||
GOOS=${TARGETOS} \ | ||
GOARCH=${TARGETARCH} \ | ||
go build \ | ||
-trimpath \ | ||
-ldflags="-s -w -X github.com/pluralsh/deployment-operator/pkg/harness/environment.Version=${VERSION}" \ | ||
-o /plural/harness \ | ||
cmd/harness/main.go | ||
|
||
FROM busybox:1.35.0-uclibc as environment | ||
|
||
RUN mkdir /plural | ||
RUN mkdir /tmp/plural | ||
|
||
FROM gcr.io/distroless/base-debian12:nonroot as final | ||
|
||
# Switch to the nonroot user | ||
USER nonroot:nonroot | ||
|
||
# Set up the environment | ||
# 1. copy plural and tmp directories with proper permissions for the nonroot user | ||
# 2. copy the static shell and sleep binary into base image <- TODO: this should not be required for prod image | ||
# 3. copy the harness binary | ||
# 4. copy the terraform binary | ||
COPY --chown=nonroot --from=environment /plural /plural | ||
COPY --chown=nonroot --from=environment /tmp/plural /tmp | ||
COPY --chown=nonroot --from=environment /bin/sh /bin/sh | ||
COPY --chown=nonroot --from=environment /bin/sleep /bin/sleep | ||
COPY --from=builder /plural/harness /harness | ||
|
||
ENTRYPOINT ["/harness", "--working-dir=plural"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ARG TERRAFORM_IMAGE_TAG=1.8.2 | ||
ARG TERRAFORM_IMAGE=hashicorp/terraform:$TERRAFORM_IMAGE_TAG | ||
|
||
ARG HARNESS_BASE_IMAGE_TAG=latest | ||
ARG HARNESS_BASE_IMAGE_REPO=harness-base | ||
ARG HARNESS_BASE_IMAGE=$HARNESS_BASE_IMAGE_REPO:$HARNESS_BASE_IMAGE_TAG | ||
|
||
FROM $TERRAFORM_IMAGE as terraform | ||
FROM $HARNESS_BASE_IMAGE as final | ||
|
||
COPY --from=terraform /bin/terraform /bin/terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package stacks | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
console "github.com/pluralsh/console-client-go" | ||
"github.com/pluralsh/deployment-operator/pkg/test/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func TestGetDefaultContainerImage(t *testing.T) { | ||
var kClient client.Client | ||
fakeConsoleClient := mocks.NewClientMock(t) | ||
namespace := "default" | ||
reconciler := NewStackReconciler(fakeConsoleClient, kClient, time.Minute, namespace, "", "") | ||
run := &console.StackRunFragment{ | ||
Type: console.StackTypeTerraform, | ||
Configuration: &console.StackConfigurationFragment{ | ||
Version: "1.8.4", | ||
}, | ||
} | ||
|
||
img := reconciler.getDefaultContainerImage(run) | ||
assert.Equal(t, img, "ghcr.io/pluralsh/harness:0.4.28-terraform-1.8.4") | ||
} |