Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
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
8 changes: 4 additions & 4 deletions apps/nodectrl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ ARG APP
RUN mkdir -p ./apps/$APP
WORKDIR /tmp/app/apps/$APP
COPY --chown=1001 ./ ./
RUN CGO_ENABLED=0 go build -tags musl -o /tmp/bin/$APP ./main.go
RUN CGO_ENABLED=0 go build -o /tmp/bin/$APP ./main.go
RUN chmod +x /tmp/bin/$APP

#FROM gcr.io/distroless/static-debian11
FROM alpine
RUN adduser -D -h /home/nonroot nonroot
RUN apk add curl git openssh-client
RUN cd bin && curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && chmod +x kubectl
RUN cd bin && curl -o tf.zip https://releases.hashicorp.com/terraform/1.2.9/terraform_1.2.9_linux_amd64.zip && unzip tf.zip
RUN cd /usr/local/bin && curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && chmod +x kubectl
RUN cd /usr/local/bin && curl -o tf.zip https://releases.hashicorp.com/terraform/1.2.9/terraform_1.2.9_linux_amd64.zip && unzip tf.zip && rm tf.zip
# RUN cd bin && curl -L0 -o talosctl https://github.com/siderolabs/talos/releases/download/v1.2.3/talosctl-linux-amd64 && chmod +x talosctl
USER nonroot
WORKDIR /tmp/app
COPY --chown=nonroot --from=base /tmp/bin/nodectrl ./nodectrl
COPY --chown=nonroot --from=project-root ./pkg/infraClient/terraform /templates/terraform
# COPY --chown=nonroot --from=project-root ./pkg/infraClient/terraform /templates/terraform
# COPY --chown=nonroot --from=project-root ./pkg/infraClient/templates /tmp/app/pkg/infraClient/templates
CMD ["./nodectrl"]
52 changes: 52 additions & 0 deletions apps/nodectrl/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ version: "3"
dotenv:
- .secrets/env

vars:
ImagePrefix: ghcr.io/kloudlite/platform/apis

tasks:
gen-sec:
sources:
Expand Down Expand Up @@ -31,3 +34,52 @@ tasks:
cmds:
- docker buildx build -f ./Dockerfile -t {{.IMAGE}} . --build-arg APP={{.APP}} --platform linux/amd64 --build-context project-root=../..
- docker push {{.IMAGE}}

build:
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
preconditions:
- sh: '[ -n "{{.Out}}" ]'
msg: var Out must have a value
cmds:
- go build -ldflags="-s -w" -o {{.Out}}
- upx {{.Out}}

local-build:
vars:
APP: nodectrl
IMAGE: "{{.ImagePrefix}}/{{.APP}}:{{.Tag}}"
preconditions:
- sh: '[[ -n "{{.Tag}}" ]]'
msg: 'var Tag must have a value'
cmds:
- |+
lineNumbers=$(cat Dockerfile | grep -i '^FROM' -n | tail +2 | awk -F: '{print $1}')

startLineNo=$(echo "$lineNumbers" | head -n+1)
finalLineNo=$(echo "$lineNumbers" | tail -1)

tDir=$(mktemp -d)

# nDockerfile=$(cat Dockerfile | tail --lines=+$startLineNo | grep -i --invert-match 'from=base')
nDockerfile=$(cat Dockerfile | tail --lines=+$startLineNo)
echo "$nDockerfile" | sed "1 i # syntax=docker/dockerfile:1.4" > $tDir/Dockerfile.base

lineNo=$(cat $tDir/Dockerfile.base | grep -i '[-][-]from=base' -n | awk -F: '{print $1}')

echo "line no. is $lineNo"

cat $tDir/Dockerfile.base | grep -i --invert-match 'from=base' > $tDir/Dockerfile.base2

cat $tDir/Dockerfile.base2 | sed "$lineNo i COPY --from=local-builder ./{{.APP}} /{{.APP}}" > $tDir/Dockerfile
cat $tDir/Dockerfile

echo "building application ..."
task build Out=$tDir/{{.APP}}

docker buildx build -f $tDir/Dockerfile -t {{.IMAGE}} . --build-context local-builder=${tDir}
docker push {{.IMAGE}}
rm -rf $tDir