-
Notifications
You must be signed in to change notification settings - Fork 11
/
Earthfile
155 lines (130 loc) · 6.1 KB
/
Earthfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
VERSION --wildcard-builds 0.8
FROM busybox
ARG --global UID=1000
ARG --global target=docker
deps:
ARG USERARCH
IF [ "$USERARCH" = "arm64" ]
FROM golang:1.21-bookworm
RUN apt update && apt install --auto-remove ca-certificates tzdata libgit2-dev libsqlite3-dev -y
ELSE
FROM golang:1.21-alpine3.18
RUN apk add --no-cache ca-certificates tzdata bash libgit2-dev sqlite-dev alpine-sdk
END
COPY buf_sha256.txt .
ARG BUF_VERSION=v1.26.1
ARG BUF_BIN_PATH=/usr/local/bin
RUN OS=Linux ARCH=$(uname -m) && \
wget "https://github.com/bufbuild/buf/releases/download/${BUF_VERSION}/buf-${OS}-${ARCH}" \
-O "${BUF_BIN_PATH}/buf" && \
chmod +x "${BUF_BIN_PATH}/buf"
RUN OS=Linux ARCH=$(uname -m) && \
SHA=$(cat buf_sha256.txt | grep "buf-${OS}-${ARCH}$" | cut -d ' ' -f1) && \
echo "${SHA} ${BUF_BIN_PATH}/buf" | sha256sum -c
ARG GO_CI_LINT_VERSION="v1.51.2"
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@$GO_CI_LINT_VERSION
RUN wget https://github.com/GaijinEntertainment/go-exhaustruct/archive/refs/tags/v3.2.0.tar.gz -O exhaustruct.tar.gz
RUN echo 511d0ba05092386a59dca74b6cbeb99f510b814261cc04b68213a9ae31cf8bf6 exhaustruct.tar.gz | sha256sum -c
RUN tar xzf exhaustruct.tar.gz
WORKDIR go-exhaustruct-3.2.0
RUN go build ./cmd/exhaustruct
RUN mv exhaustruct /usr/local/bin/exhaustruct
WORKDIR /kp
RUN mkdir -p database/migrations
COPY database/migrations database/migrations
COPY go.mod go.sum ./
RUN go mod download
SAVE ARTIFACT go.mod
SAVE ARTIFACT go.sum
SAVE ARTIFACT $BUF_BIN_PATH/buf
migration-deps:
FROM scratch
COPY database/ database/
SAVE ARTIFACT database/migrations
cd-service:
BUILD ./services/cd-service+$target --UID=$UID --service=cd-service
manifest-repo-export-service:
BUILD ./services/manifest-repo-export-service+$target --UID=$UID --service=manifest-repo-export-service
rollout-service:
BUILD ./services/rollout-service+$target --UID=$UID --service=rollout-service
frontend-service:
BUILD ./services/frontend-service+$target --UID=$UID --service=frontend-service
ui:
BUILD ./services/frontend-service+$target-ui
all-services:
ARG tag="local"
BUILD ./pkg+deps
BUILD ./services/*+docker --tag=$tag --UID=$UID
BUILD ./services/frontend-service+docker-ui
commitlint:
FROM node:18-bookworm
WORKDIR /commitlint/
RUN npm install --save-dev @commitlint/[email protected]
WORKDIR /commitlint/
COPY commitlint.config.js commitlint.config.js
COPY commitlint.msg commitlint.msg
RUN cat ./commitlint.msg | npx commitlint --config commitlint.config.js
test-all:
BUILD ./services/cd-service+unit-test --service=cd-service
BUILD ./services/manifest-repo-export-service+unit-test --service=manifest-repo-export-service
BUILD ./services/rollout-service+unit-test --service=rollout-service
BUILD ./services/frontend-service+unit-test --service=frontend-service
BUILD ./services/frontend-service+unit-test-ui
integration-test-deps:
FROM alpine/k8s:1.25.15
RUN wget -O "/usr/bin/argocd" https://github.com/argoproj/argo-cd/releases/download/v2.7.5/argocd-linux-amd64 && \
echo "a7680140ddb9011c3d282eaff5f5a856be18e8653ff9f0c7047a318f640753be /usr/bin/argocd" | sha256sum -c - && \
chmod +x "/usr/bin/argocd"
SAVE ARTIFACT /usr/bin/kubectl
SAVE ARTIFACT /usr/bin/helm
SAVE ARTIFACT /usr/bin/argocd
integration-test:
FROM golang:1.21-bookworm
RUN apt update && apt install --auto-remove -y curl gpg gpg-agent gettext bash git golang netcat-openbsd docker.io
ARG GO_TEST_ARGS
# K3S environment variables
ENV KUBECONFIG=/kp/kubeconfig.yaml
ENV K3S_TOKEN="Random"
# Kuberpult/ArgoCd environment variables
ENV ARGO_NAMESPACE=default
# Git environment variables
ENV GIT_NAMESPACE=git
ENV SSH_HOST_PORT=2222
ENV GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=emptyfile -o StrictHostKeyChecking=no -i /kp/client'
ENV GIT_AUTHOR_NAME='Initial Kuberpult Commiter'
ENV GIT_COMMITTER_NAME='Initial Kuberpult Commiter'
ENV GIT_AUTHOR_EMAIL='[email protected]'
ENV GIT_COMMITTER_EMAIL='[email protected]'
WORKDIR /kp
COPY +integration-test-deps/* /usr/bin/
COPY tests/integration-tests/cluster-setup/docker-compose-k3s.yml .
COPY go.mod go.sum .
RUN go mod download
RUN --no-cache echo GPG gen starting...
RUN --no-cache gpg --keyring trustedkeys-kuberpult.gpg --no-default-keyring --batch --passphrase '' --quick-gen-key [email protected]
RUN --no-cache echo GPG export starting...
RUN --no-cache gpg --keyring trustedkeys-kuberpult.gpg --armor --export [email protected] > /kp/kuberpult-keyring.gpg
# Note that multiple commands here are writing to "." which is slightly dangerous, because
# if there are files with the same name, old ones will be overridden.
COPY charts/kuberpult .
COPY database/migrations database/migrations
COPY infrastructure/scripts/create-testdata/testdata_template/environments environments
COPY infrastructure/scripts/create-testdata/create-release.sh .
COPY tests/integration-tests tests/integration-tests
COPY ./pkg+artifacts/pkg pkg
ARG --required kuberpult_version
ENV VERSION=$kuberpult_version
ARG --required charts_version
ENV CHARTS_VERSION=$charts_version
RUN envsubst < Chart.yaml.tpl > Chart.yaml
WITH DOCKER --compose docker-compose-k3s.yml
RUN --no-cache \
set -e; \
echo Waiting for K3s cluster to be ready; \
sleep 10 && kubectl wait --for=condition=Ready nodes --all --timeout=300s && sleep 3; \
./tests/integration-tests/cluster-setup/setup-cluster-ssh.sh& \
./tests/integration-tests/cluster-setup/setup-postgres.sh && \
./tests/integration-tests/cluster-setup/argocd-kuberpult.sh && \
cd tests/integration-tests && go test $GO_TEST_ARGS ./... || ./cluster-setup/get-logs.sh; \
echo ============ SUCCESS ============
END