Skip to content

Commit

Permalink
chore: add skaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
WitoDelnat committed Oct 25, 2024
1 parent ad99718 commit 836546e
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 10 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.git
.gitignore
.github
LICENSE
README.md
Makefile
build
Expand Down
2 changes: 1 addition & 1 deletion build/_local/agent-server.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FROM scratch AS dist

COPY LICENSE /testkube/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /app/build/_local/cloud-api /testkube/
COPY --from=builder /app/build/_local/agent-server /testkube/

EXPOSE 8080
ENTRYPOINT ["/testkube/agent-server"]
63 changes: 63 additions & 0 deletions build/_local/testworkflow-init.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
ARG BUSYBOX_IMAGE="busybox:1.36.1-musl"

###################################
## Build testworkflow init
###################################
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder

ARG TARGETOS
ARG TARGETARCH
ARG GOMODCACHE="/root/.cache/go-build"
ARG GOCACHE="/go/pkg"
ARG SKAFFOLD_GO_GCFLAGS

WORKDIR /app
COPY . .
RUN --mount=type=cache,target="$GOMODCACHE" \
--mount=type=cache,target="$GOCACHE" \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
CGO_ENABLED=0 \
go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o build/_local/workflow-init cmd/testworkflow-init/main.go

###################################
## Build testworkflow toolkit
###################################
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder

ARG TARGETOS
ARG TARGETARCH
ARG GOMODCACHE="/root/.cache/go-build"
ARG GOCACHE="/go/pkg"
ARG SKAFFOLD_GO_GCFLAGS

WORKDIR /app
COPY . .
RUN --mount=type=cache,target="$GOMODCACHE" \
--mount=type=cache,target="$GOCACHE" \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
CGO_ENABLED=0 \
go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o build/_local/workflow-init cmd/testworkflow-init/main.go

###################################
## Debug
###################################
FROM golang:1.23-alpine AS debug

ENV GOTRACEBACK=all
RUN go install github.com/go-delve/delve/cmd/[email protected]

COPY --from=builder /app/build/_local/workflow-init /testkube/

ENTRYPOINT ["/go/bin/dlv", "exec", "--headless", "--continue", "--accept-multiclient", "--listen=:56268", "--api-version=2", "/testkube/workflow-init"]

###################################
## Distribution
###################################
FROM ${BUSYBOX_IMAGE} AS dist
RUN cp -rf /bin /.tktw-bin
COPY --from=builder /app/build/_local/workflow-init /testkube/init
USER 1001
ENTRYPOINT ["/init"]

71 changes: 71 additions & 0 deletions build/_local/testworkflow-toolkit.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ARG BUSYBOX_IMAGE="busybox:1.36.1-musl"
ARG ALPINE_IMAGE="alpine:3.20.0"
FROM ${BUSYBOX_IMAGE} AS busybox

###################################
## Build testworkflow-init
###################################
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder-init

ARG TARGETOS
ARG TARGETARCH
ARG GOMODCACHE="/root/.cache/go-build"
ARG GOCACHE="/go/pkg"
ARG SKAFFOLD_GO_GCFLAGS

WORKDIR /app
COPY . .
RUN --mount=type=cache,target="$GOMODCACHE" \
--mount=type=cache,target="$GOCACHE" \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
CGO_ENABLED=0 \
go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o build/_local/workflow-init cmd/testworkflow-init/main.go

###################################
## Build testworkflow-toolkit
###################################
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder-toolkit

ARG TARGETOS
ARG TARGETARCH
ARG GOMODCACHE="/root/.cache/go-build"
ARG GOCACHE="/go/pkg"
ARG SKAFFOLD_GO_GCFLAGS

RUN go install github.com/go-delve/delve/cmd/[email protected]

WORKDIR /app
COPY . .
RUN --mount=type=cache,target="$GOMODCACHE" \
--mount=type=cache,target="$GOCACHE" \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
CGO_ENABLED=0 \
go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o build/_local/workflow-toolkit cmd/testworkflow-toolkit/main.go

###################################
## Debug
###################################
FROM ${ALPINE_IMAGE} AS debug
RUN apk --no-cache add ca-certificates libssl3 git openssh-client
ENV GOTRACEBACK=all
COPY --from=builder-toolkit /go/bin/dlv /
COPY --from=busybox /bin /.tktw-bin
COPY --from=builder-toolkit /app/build/_local/workflow-toolkit /toolkit
COPY --from=builder-init /app/build/_local/workflow-init /init
RUN adduser --disabled-password --home / --no-create-home --uid 1001 default
USER 1001
ENTRYPOINT ["/dlv", "exec", "--headless", "--accept-multiclient", "--listen=:56300", "--api-version=2", "/toolkit"]

###################################
## Distribution
###################################
FROM ${ALPINE_IMAGE} AS dist
RUN apk --no-cache add ca-certificates libssl3 git openssh-client
COPY --from=busybox /bin /.tktw-bin
COPY --from=builder-toolkit /app/build/_local/workflow-toolkit /toolkit
COPY --from=builder-init /app/build/_local/workflow-init /init
RUN adduser --disabled-password --home / --no-create-home --uid 1001 default
USER 1001
ENTRYPOINT ["/toolkit"]
30 changes: 26 additions & 4 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ variable "GOMODCACHE" {
}

group "default" {
targets = ["agent-server"]
targets = ["agent-server", "testworkflow-init", "testworkflow-toolkit"]
}

target "agent-server-meta" {
tags = ["kubeshop/tk-agent-server:dev"]
}
target "agent-server-meta" {}
target "agent-server" {
inherits = ["agent-server-meta"]
context="."
Expand All @@ -22,3 +20,27 @@ target "agent-server" {
GOMODCACHE = "${GOMODCACHE}"
}
}

target "testworkflow-init-meta" {}
target "testworkflow-init" {
inherits = ["testworkflow-init-meta"]
context="."
dockerfile = "build/_local/testworkflow-init.Dockerfile"
platforms = ["linux/arm64"]
args = {
GOCACHE = "${GOCACHE}"
GOMODCACHE = "${GOMODCACHE}"
}
}

target "testworkflow-toolkit-meta" {}
target "testworkflow-toolkit" {
inherits = ["testworkflow-toolkit-meta"]
context="."
dockerfile = "build/_local/testworkflow-toolkit.Dockerfile"
platforms = ["linux/arm64"]
args = {
GOCACHE = "${GOCACHE}"
GOMODCACHE = "${GOMODCACHE}"
}
}
4 changes: 3 additions & 1 deletion pkg/event/bus/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

var (
_ Bus = (*NATSBus)(nil)

NATS_RETRY_ATTEMPTS uint = 20
)

const (
Expand Down Expand Up @@ -89,7 +91,7 @@ func NewNATSConnection(cfg ConnectionConfig, opts ...nats.Option) (*nats.Conn, e
},
retry.DelayType(retry.FixedDelay),
retry.Delay(utils.DefaultRetryDelay),
retry.Attempts(20),
retry.Attempts(NATS_RETRY_ATTEMPTS),
)
if err != nil {
log.DefaultLogger.Fatalw("error connecting to nats", "error", err)
Expand Down
28 changes: 25 additions & 3 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: Config
metadata:
name: testkube-agent
build:
local:
concurrency: 1 # for testing, should be possible to run all concurrently.
artifacts:
- image: docker.io/testkube-agent-server
context: .
Expand All @@ -11,6 +13,20 @@ build:
dependencies:
dockerfile:
path: build/_local/agent-server.Dockerfile
- image: docker.io/testworkflow-init
context: .
custom:
buildCommand: GOCACHE="$(go env GOCACHE)" GOMODCACHE="$(go env GOMODCACHE)" docker buildx bake --set testworkflow-init.tags="$IMAGE" testworkflow-init
dependencies:
dockerfile:
path: build/_local/testworkflow-init.Dockerfile
- image: docker.io/testworkflow-toolkit
context: .
custom:
buildCommand: GOCACHE="$(go env GOCACHE)" GOMODCACHE="$(go env GOMODCACHE)" docker buildx bake --set testworkflow-toolkit.tags="$IMAGE" --set testworkflow-toolkit.target="debug" testworkflow-toolkit
dependencies:
dockerfile:
path: build/_local/testworkflow-toolkit.Dockerfile
deploy:
helm:
# see https://skaffold.dev/docs/renderers/helm/#skaffoldyaml-configuration
Expand All @@ -19,17 +35,23 @@ deploy:
repo: https://kubeshop.github.io/helm-charts
remoteChart: testkube
# Alternative: Local chart - useful for when you are actively making changes to the chart.
# chartPath: /Users/you/code/helm-charts/charts/testkube-api
# chartPath: /Users/you/path/to/helm-charts/charts/testkube
upgradeOnChange: true
skipBuildDependencies: true # This implies that you need to build dependencies yourself when you make local chart changes!
# skipBuildDependencies: true # This implies that you need to build dependencies yourself when you make local chart changes!
namespace: tk-dev
wait: true
createNamespace: true
valuesFiles: ['build/_local/values.dev.yaml'] # IMPORTANT: You will have to copy the values.dev.tpl.yaml template to get started!
setValueTemplates:
testkube-api.image.registry: '{{.IMAGE_DOMAIN_docker_io_testkube_agent_server}}'
testkube-api.image.repository: '{{.IMAGE_REPO_NO_DOMAIN_docker_io_testkube_agent_server}}'
testkube-api.image.tag: '{{.IMAGE_TAG_docker_io_testkube_agent_server}}@{{.IMAGE_DIGEST_docker_io_testkube_agent_server}}'
testkube-api.image.tag: '{{.IMAGE_TAG_docker_io_testkube_agent_server}}@{{.IMAGE_DIGEST_docker_io_testkube_agent_server}}'
testkube-api.imageTwInit.registry: '{{.IMAGE_DOMAIN_docker_io_testworkflow_init}}'
testkube-api.imageTwInit.repository: '{{.IMAGE_REPO_NO_DOMAIN_docker_io_testworkflow_init}}'
testkube-api.imageTwInit.tag: '{{.IMAGE_TAG_docker_io_testworkflow_init}}@{{.IMAGE_DIGEST_docker_io_testworkflow_init}}'
testkube-api.imageTwToolkit.registry: '{{.IMAGE_DOMAIN_docker_io_testworkflow_toolkit}}'
testkube-api.imageTwToolkit.repository: '{{.IMAGE_REPO_NO_DOMAIN_docker_io_testworkflow_toolkit}}'
testkube-api.imageTwToolkit.tag: '{{.IMAGE_TAG_docker_io_testworkflow_toolkit}}@{{.IMAGE_DIGEST_docker_io_testworkflow_toolkit}}'
flags:
upgrade: ["--no-hooks"]
statusCheckDeadlineSeconds: 300
Expand Down

0 comments on commit 836546e

Please sign in to comment.