generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
258 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_output/ |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
.DS_Store | ||
/.vscode/* | ||
|
||
_output/ | ||
/hack/tools/bin/ |
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,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
# Ensure the go tool exists and is a viable version. | ||
verify_go_version() { | ||
if [[ -z "$(command -v go)" ]]; then | ||
cat >&2 <<EOF | ||
Can't find 'go' in PATH, please fix and retry. | ||
See http://golang.org/doc/install for installation instructions. | ||
EOF | ||
return 2 | ||
fi | ||
|
||
if [[ -z "${MINIMUM_GO_VERSION:-}" ]]; then | ||
return 0 | ||
fi | ||
|
||
local go_version | ||
IFS=" " read -ra go_version <<< "$(go version)" | ||
if [[ "${MINIMUM_GO_VERSION}" != $(echo -e "${MINIMUM_GO_VERSION}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then | ||
cat >&2 <<EOF | ||
Detected go version: ${go_version[*]}. | ||
Boskos requires ${MINIMUM_GO_VERSION} or greater. | ||
Please install ${MINIMUM_GO_VERSION} or later. | ||
EOF | ||
return 2 | ||
fi | ||
} | ||
|
||
verify_go_version |
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,38 @@ | ||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Installs a few extra tools folks might want to use when running boskosctl. | ||
|
||
ARG go_version | ||
ARG alpine_version=3.11 | ||
|
||
FROM golang:${go_version}-alpine${alpine_version} as build | ||
WORKDIR /go/src/app | ||
|
||
RUN apk add bash make | ||
|
||
# Cache module downloads | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
RUN go mod download | ||
|
||
COPY . . | ||
RUN make build WHAT=./cmd/boskosctl | ||
|
||
FROM alpine:${alpine_version} | ||
|
||
RUN apk add bash jq | ||
|
||
COPY --from=build "/go/src/app/_output/bin/boskosctl" /bin/boskosctl | ||
ENTRYPOINT ["/bin/boskosctl"] |
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,62 @@ | ||
#!/bin/bash | ||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This takes in environment variables and outputs data used by Bazel | ||
# to set key-value pairs | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
if [[ -z "${DOCKER_REPO:-}" ]]; then | ||
echo "DOCKER_REPO must be set!" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "${DOCKER_TAG:-}" ]]; then | ||
echo "DOCKER_TAG must be set!" >&2 | ||
exit 1 | ||
fi | ||
|
||
docker_build() { | ||
local binary=$1 | ||
local package | ||
# TODO(ixdy): fix project layout for aws-janitor binaries | ||
case "${binary}" in | ||
aws-janitor) | ||
package="./aws-janitor" | ||
;; | ||
aws-janitor-boskos) | ||
package="./aws-janitor/cmd/aws-janitor-boskos" | ||
;; | ||
*) | ||
package="./cmd/${binary}" | ||
esac | ||
local image_dir | ||
if [[ -d ./images/"${binary}" ]]; then | ||
image_dir="${binary}" | ||
else | ||
image_dir="default" | ||
fi | ||
docker build --pull \ | ||
--build-arg "go_version=${GO_VERSION}" \ | ||
--build-arg "package=${package}" \ | ||
--build-arg "binary=${binary}" \ | ||
-t "${DOCKER_REPO}/${binary}:${DOCKER_TAG}" \ | ||
-t "${DOCKER_REPO}/${binary}:latest" \ | ||
-f "./images/${image_dir}/Dockerfile" . | ||
} | ||
|
||
docker_build $@ |
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,37 @@ | ||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Most of the images can be based on distroless, which is fairly lightweight. | ||
|
||
ARG go_version | ||
|
||
FROM golang:${go_version} as build | ||
WORKDIR /go/src/app | ||
|
||
# Cache module downloads | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
RUN go mod download | ||
|
||
COPY . . | ||
# Cache build output too | ||
RUN make build | ||
|
||
ARG package | ||
RUN make build WHAT="${package}" | ||
|
||
FROM gcr.io/distroless/base-debian10 | ||
ARG binary | ||
COPY --from=build "/go/src/app/_output/bin/${binary}" /app | ||
ENTRYPOINT ["/app"] |
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,41 @@ | ||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# The GCP janitor requires gcloud, so this image is based on the google cloud-sdk image. | ||
|
||
ARG go_version | ||
|
||
FROM golang:${go_version} as build | ||
WORKDIR /go/src/app | ||
|
||
# Cache module downloads | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
RUN go mod download | ||
|
||
COPY . . | ||
# Cache build output too | ||
RUN make build | ||
|
||
ARG package | ||
RUN make build WHAT="${package}" | ||
|
||
FROM gcr.io/google.com/cloudsdktool/cloud-sdk:277.0.0-slim | ||
ARG binary | ||
COPY ./cmd/janitor/gcp_janitor.py /bin | ||
COPY --from=build "/go/src/app/_output/bin/${binary}" /bin/janitor | ||
|
||
# the entrypoint must be sh | ||
# https://github.com/kubernetes/test-infra/issues/5877 | ||
ENTRYPOINT ["/bin/sh", "-c", "/bin/echo starting janitor && /bin/janitor \"$@\"", "--"] |