diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de69680..8646817 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,14 +16,12 @@ jobs: build: name: Build runs-on: ubuntu-24.04 + strategy: + matrix: + provider: [capa, capg, caph, capz] steps: - uses: actions/checkout@v1 - - name: Print version info - id: semver - run: | - make version - - name: Set up QEMU id: qemu uses: docker/setup-qemu-action@v1 @@ -40,8 +38,10 @@ jobs: - name: Run checks run: | + cd ${{ matrix.provider }} make ci - name: Build run: | + cd ${{ matrix.provider }} make release diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4f1f9a8..0000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM alpine - -ARG TARGETOS -ARG TARGETARCH - -LABEL org.opencontainers.image.source https://github.com/kluster-api/capi-scripts - -RUN apk add --no-cache bash curl ca-certificates - -COPY scripts /tmp/scripts diff --git a/README.md b/README.md index 8cb172b..2eb8319 100644 --- a/README.md +++ b/README.md @@ -1,3 +1 @@ -# capi-scripts - -* `make release` +# capi-deployer diff --git a/capa/Dockerfile b/capa/Dockerfile new file mode 100644 index 0000000..5621cbc --- /dev/null +++ b/capa/Dockerfile @@ -0,0 +1,19 @@ +FROM alpine AS builder + +LABEL org.opencontainers.image.source=https://github.com/kluster-api/capi-deployer + +ARG TARGETOS +ARG TARGETARCH + +ARG CLUSTERCTL="v1.6.3" +ARG CLUSTERAWSADM_VERSION="v2.4.2" +ARG INFRASTRUCTURE_VERSION="v2.4.2" +ARG CLUSTER_API_VERSION="v1.6.3" +ARG IAM_AUTHENTICATOR_VERSION="0.6.14" + +RUN apk add --update --no-cache bash ca-certificates curl openssl unzip wget + +COPY script.sh . + +RUN chmod +x script.sh +RUN ./script.sh diff --git a/Makefile b/capa/Makefile similarity index 97% rename from Makefile rename to capa/Makefile index 8c56f84..c6b65d4 100644 --- a/Makefile +++ b/capa/Makefile @@ -1,7 +1,7 @@ SHELL=/bin/bash -o pipefail REGISTRY ?= ghcr.io/appscode -BIN ?= capi-scripts +BIN ?= $(notdir $(shell pwd))-deployer IMAGE := $(REGISTRY)/$(BIN) TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "") diff --git a/providers/aws/README.md b/capa/README.md similarity index 100% rename from providers/aws/README.md rename to capa/README.md diff --git a/providers/aws/script.sh b/capa/script.sh similarity index 94% rename from providers/aws/script.sh rename to capa/script.sh index 7d94497..7cce447 100644 --- a/providers/aws/script.sh +++ b/capa/script.sh @@ -1,11 +1,6 @@ #!/bin/bash - -HOME="/home/ubuntu" -cd /root set -xeo pipefail -apt-get -y update - PROVIDER_NAME=aws SERVICE_NAME=eks-managedmachinepool @@ -34,9 +29,11 @@ if [[ "$OSTYPE" == linux* ]]; then elif [[ "$OSTYPE" == darwin* ]]; then opsys=darwin fi + timestamp() { date +"%Y/%m/%d %T" } + log() { local type="$1" local msg="$2" @@ -63,10 +60,6 @@ retry() { return 0 } -install_wget() { - apt install wget -} - install_nats-logger() { curl -fsSLO https://github.com/bytebuilders/nats-logger/releases/latest/download/nats-logger-linux-amd64.tar.gz tar -xzvf nats-logger-linux-amd64.tar.gz @@ -87,10 +80,11 @@ install_kubectl() { ltral="https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${opsys}/${sys_arch}/kubectl.sha256" cmnd="curl -LO" retry 5 ${cmnd} ${ltral} - echo "$(cat kubectl.sha256) kubectl" | sha256sum --check + echo "$(cat kubectl.sha256) kubectl" | sha256sum -c cmnd="install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl" retry 5 ${cmnd} } + install_helm() { local cmnd="curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3" retry 5 ${cmnd} @@ -98,6 +92,7 @@ install_helm() { cmnd="./get_helm.sh" retry 5 ${cmnd} } + install_clusterctl() { local cmnd="curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTERCTL}/clusterctl-${opsys}-${sys_arch} -o clusterctl" retry 5 ${cmnd} @@ -113,6 +108,7 @@ install_clusterawsadm() { mv clusterawsadm /usr/local/bin clusterawsadm version } + install_aws_iam_authenticator() { local cmnd="curl -Lo aws-iam-authenticator https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v${IAM_AUTHENTICATOR_VERSION}/aws-iam-authenticator_${IAM_AUTHENTICATOR_VERSION}_${opsys}_${sys_arch}" retry 5 ${cmnd} @@ -155,14 +151,13 @@ EOF } install_aws_cli() { - apt install unzip >/dev/null - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" >/dev/null - unzip awscliv2.zip >/dev/null - ./aws/install >/dev/null + # curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" >/dev/null + # unzip awscliv2.zip >/dev/null + # ./aws/install >/dev/null + apk add --update --no-cache aws-cli } init() { - install_wget install_nats-logger install_capi-config install_kubectl diff --git a/capg/Dockerfile b/capg/Dockerfile new file mode 100644 index 0000000..e9be099 --- /dev/null +++ b/capg/Dockerfile @@ -0,0 +1,18 @@ +FROM alpine AS builder + +LABEL org.opencontainers.image.source=https://github.com/kluster-api/capi-deployer + +ARG TARGETOS +ARG TARGETARCH + +ARG CLUSTERCTL="v1.6.3" +ARG INFRASTRUCTURE_VERSION="v1.6.0" +ARG CLUSTER_API_VERSION="v1.6.3" +ARG YQ_VERSION="v4.2.0" + +RUN apk add --update --no-cache bash ca-certificates curl openssl unzip wget + +COPY script.sh . + +RUN chmod +x script.sh +RUN ./script.sh diff --git a/capg/Makefile b/capg/Makefile new file mode 100644 index 0000000..c6b65d4 --- /dev/null +++ b/capg/Makefile @@ -0,0 +1,68 @@ +SHELL=/bin/bash -o pipefail + +REGISTRY ?= ghcr.io/appscode +BIN ?= $(notdir $(shell pwd))-deployer +IMAGE := $(REGISTRY)/$(BIN) +TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "") + +DOCKER_PLATFORMS := linux/amd64 linux/arm64 +PLATFORM ?= linux/$(subst x86_64,amd64,$(subst aarch64,arm64,$(shell uname -m))) +VERSION = $(TAG)_$(subst /,_,$(PLATFORM)) + +container-%: + @$(MAKE) container \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +push-%: + @$(MAKE) push \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +all-container: $(addprefix container-, $(subst /,_,$(DOCKER_PLATFORMS))) + +all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS))) + +.PHONY: container +container: + @echo "container: $(IMAGE):$(VERSION)" + @docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(VERSION) -f Dockerfile . + @echo + +push: container + @docker push $(IMAGE):$(VERSION) + @echo "pushed: $(IMAGE):$(VERSION)" + @echo + +.PHONY: docker-manifest +docker-manifest: + docker manifest create -a $(IMAGE):$(TAG) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(TAG)_$(subst /,_,$(PLATFORM))) + docker manifest push $(IMAGE):$(TAG) + +.PHONY: release +release: + @$(MAKE) all-push docker-manifest --no-print-directory + +.PHONY: version +version: + @echo version=$(VERSION) + +.PHONY: fmt +fmt: + @find . -path ./vendor -prune -o -name '*.sh' -exec shfmt -l -w -ci -i 4 {} \; + +.PHONY: verify +verify: fmt + @if !(git diff --exit-code HEAD); then \ + echo "files are out of date, run make fmt"; exit 1; \ + fi + +.PHONY: ci +ci: verify + +# make and load docker image to kind cluster +.PHONY: push-to-kind +push-to-kind: container + @echo "Loading docker image into kind cluster...." + @kind load docker-image $(IMAGE):$(VERSION) + @echo "Image has been pushed successfully into kind cluster." diff --git a/providers/gcp/README.md b/capg/README.md similarity index 100% rename from providers/gcp/README.md rename to capg/README.md diff --git a/providers/gcp/script.sh b/capg/script.sh similarity index 96% rename from providers/gcp/script.sh rename to capg/script.sh index 00c64e7..1e8f850 100644 --- a/providers/gcp/script.sh +++ b/capg/script.sh @@ -1,11 +1,6 @@ #!/bin/bash - -HOME="/home/ubuntu" -cd /root set -xeo pipefail -apt-get -y update - PROVIDER_NAME=gcp SERVICE_NAME=gke @@ -66,14 +61,10 @@ retry() { return 0 } -install_wget() { - apt install wget -} - install_yq() { BINARY="yq_linux_amd64" - wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${BINARY}.tar.gz -O - |\ - tar xz && mv ${BINARY} /bin/yq + wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${BINARY}.tar.gz -O - | + tar xz && mv ${BINARY} /bin/yq } install_nats-logger() { @@ -100,7 +91,7 @@ install_kubectl() { cmnd="curl -LO" retry 5 ${cmnd} ${ltral} - echo "$(cat kubectl.sha256) kubectl" | sha256sum --check + echo "$(cat kubectl.sha256) kubectl" | sha256sum -c cmnd="install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl" retry 5 ${cmnd} @@ -162,7 +153,6 @@ EOF } init() { - install_wget install_yq install_nats-logger install_capi-config diff --git a/caph/Dockerfile b/caph/Dockerfile new file mode 100644 index 0000000..8626a8f --- /dev/null +++ b/caph/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine AS builder + +LABEL org.opencontainers.image.source=https://github.com/kluster-api/capi-deployer + +ARG TARGETOS +ARG TARGETARCH + +ARG CLUSTERCTL="v1.6.3" + +RUN apk add --update --no-cache bash ca-certificates curl openssl unzip wget + +COPY script.sh . + +RUN chmod +x script.sh +RUN ./script.sh diff --git a/caph/Makefile b/caph/Makefile new file mode 100644 index 0000000..c6b65d4 --- /dev/null +++ b/caph/Makefile @@ -0,0 +1,68 @@ +SHELL=/bin/bash -o pipefail + +REGISTRY ?= ghcr.io/appscode +BIN ?= $(notdir $(shell pwd))-deployer +IMAGE := $(REGISTRY)/$(BIN) +TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "") + +DOCKER_PLATFORMS := linux/amd64 linux/arm64 +PLATFORM ?= linux/$(subst x86_64,amd64,$(subst aarch64,arm64,$(shell uname -m))) +VERSION = $(TAG)_$(subst /,_,$(PLATFORM)) + +container-%: + @$(MAKE) container \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +push-%: + @$(MAKE) push \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +all-container: $(addprefix container-, $(subst /,_,$(DOCKER_PLATFORMS))) + +all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS))) + +.PHONY: container +container: + @echo "container: $(IMAGE):$(VERSION)" + @docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(VERSION) -f Dockerfile . + @echo + +push: container + @docker push $(IMAGE):$(VERSION) + @echo "pushed: $(IMAGE):$(VERSION)" + @echo + +.PHONY: docker-manifest +docker-manifest: + docker manifest create -a $(IMAGE):$(TAG) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(TAG)_$(subst /,_,$(PLATFORM))) + docker manifest push $(IMAGE):$(TAG) + +.PHONY: release +release: + @$(MAKE) all-push docker-manifest --no-print-directory + +.PHONY: version +version: + @echo version=$(VERSION) + +.PHONY: fmt +fmt: + @find . -path ./vendor -prune -o -name '*.sh' -exec shfmt -l -w -ci -i 4 {} \; + +.PHONY: verify +verify: fmt + @if !(git diff --exit-code HEAD); then \ + echo "files are out of date, run make fmt"; exit 1; \ + fi + +.PHONY: ci +ci: verify + +# make and load docker image to kind cluster +.PHONY: push-to-kind +push-to-kind: container + @echo "Loading docker image into kind cluster...." + @kind load docker-image $(IMAGE):$(VERSION) + @echo "Image has been pushed successfully into kind cluster." diff --git a/providers/hetzner/README.md b/caph/README.md similarity index 100% rename from providers/hetzner/README.md rename to caph/README.md diff --git a/providers/hetzner/script.sh b/caph/script.sh similarity index 85% rename from providers/hetzner/script.sh rename to caph/script.sh index 371c3e2..7d1cb23 100644 --- a/providers/hetzner/script.sh +++ b/caph/script.sh @@ -1,12 +1,6 @@ #!/bin/bash -HOME="/root" -cd ${HOME} -apt-get -y update - set -xeo pipefail -VCLUSTER_VERSION="v0.20.0-beta.9" - case $(uname -m) in x86_64) sys_arch=amd64 @@ -30,6 +24,7 @@ if [[ "$OSTYPE" == linux* ]]; then elif [[ "$OSTYPE" == darwin* ]]; then opsys=darwin fi + timestamp() { date +"%Y/%m/%d %T" } @@ -74,7 +69,7 @@ install_kubectl() { ltral="https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${opsys}/${sys_arch}/kubectl.sha256" cmnd="curl -LO" retry 5 ${cmnd} ${ltral} -# echo "$(cat kubectl.sha256) kubectl" | sha256sum --check + # echo "$(cat kubectl.sha256) kubectl" | sha256sum -c cmnd="install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl" retry 5 ${cmnd} } @@ -95,20 +90,10 @@ install_clusterctl() { clusterctl version } -install_vclusterCLI() { - - local cmnd="curl -L -o vcluster https://github.com/loft-sh/vcluster/releases/download/${VCLUSTER_VERSION}/vcluster-${opsys}-${sys_arch}" - retry 5 ${cmnd} - install -c -m 0755 vcluster /usr/local/bin - rm -f vcluster - -} - init() { install_nats-logger install_kubectl install_helm install_clusterctl -# install_vclusterCLI } init diff --git a/capz/Dockerfile b/capz/Dockerfile new file mode 100644 index 0000000..71fc3b2 --- /dev/null +++ b/capz/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine AS builder + +LABEL org.opencontainers.image.source=https://github.com/kluster-api/capi-deployer + +ARG TARGETOS +ARG TARGETARCH + +ARG CLUSTERCTL="v1.6.3" +ARG INFRASTRUCTURE_VERSION="v1.14.2" +ARG CLUSTER_API_VERSION="v1.6.3" + +RUN apk add --update --no-cache bash ca-certificates curl openssl unzip wget + +COPY script.sh . + +RUN chmod +x script.sh +RUN ./script.sh diff --git a/capz/Makefile b/capz/Makefile new file mode 100644 index 0000000..c6b65d4 --- /dev/null +++ b/capz/Makefile @@ -0,0 +1,68 @@ +SHELL=/bin/bash -o pipefail + +REGISTRY ?= ghcr.io/appscode +BIN ?= $(notdir $(shell pwd))-deployer +IMAGE := $(REGISTRY)/$(BIN) +TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "") + +DOCKER_PLATFORMS := linux/amd64 linux/arm64 +PLATFORM ?= linux/$(subst x86_64,amd64,$(subst aarch64,arm64,$(shell uname -m))) +VERSION = $(TAG)_$(subst /,_,$(PLATFORM)) + +container-%: + @$(MAKE) container \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +push-%: + @$(MAKE) push \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +all-container: $(addprefix container-, $(subst /,_,$(DOCKER_PLATFORMS))) + +all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS))) + +.PHONY: container +container: + @echo "container: $(IMAGE):$(VERSION)" + @docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(VERSION) -f Dockerfile . + @echo + +push: container + @docker push $(IMAGE):$(VERSION) + @echo "pushed: $(IMAGE):$(VERSION)" + @echo + +.PHONY: docker-manifest +docker-manifest: + docker manifest create -a $(IMAGE):$(TAG) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(TAG)_$(subst /,_,$(PLATFORM))) + docker manifest push $(IMAGE):$(TAG) + +.PHONY: release +release: + @$(MAKE) all-push docker-manifest --no-print-directory + +.PHONY: version +version: + @echo version=$(VERSION) + +.PHONY: fmt +fmt: + @find . -path ./vendor -prune -o -name '*.sh' -exec shfmt -l -w -ci -i 4 {} \; + +.PHONY: verify +verify: fmt + @if !(git diff --exit-code HEAD); then \ + echo "files are out of date, run make fmt"; exit 1; \ + fi + +.PHONY: ci +ci: verify + +# make and load docker image to kind cluster +.PHONY: push-to-kind +push-to-kind: container + @echo "Loading docker image into kind cluster...." + @kind load docker-image $(IMAGE):$(VERSION) + @echo "Image has been pushed successfully into kind cluster." diff --git a/providers/azure/README.md b/capz/README.md similarity index 100% rename from providers/azure/README.md rename to capz/README.md diff --git a/providers/azure/script.sh b/capz/script.sh similarity index 97% rename from providers/azure/script.sh rename to capz/script.sh index eab97e3..748a8c1 100644 --- a/providers/azure/script.sh +++ b/capz/script.sh @@ -1,11 +1,6 @@ #!/bin/bash - -HOME="/home/ubuntu" -cd /root set -xeo pipefail -apt-get -y update - PROVIDER_NAME=azure SERVICE_NAME=aks @@ -66,10 +61,6 @@ function retry { return 0 } -install_wget() { - apt install wget -} - install_nats-logger() { curl -fsSLO https://github.com/bytebuilders/nats-logger/releases/latest/download/nats-logger-linux-amd64.tar.gz tar -xzvf nats-logger-linux-amd64.tar.gz @@ -87,7 +78,7 @@ install_kubectl() { cmnd="curl -LO" retry 5 ${cmnd} ${ltral} - echo "$(cat kubectl.sha256) kubectl" | sha256sum --check + echo "$(cat kubectl.sha256) kubectl" | sha256sum -c cmnd="install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl" retry 5 ${cmnd} @@ -104,8 +95,6 @@ install_helm() { retry 5 ${cmnd} } - - install_clusterctl() { local cmnd="curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTERCTL}/clusterctl-${opsys}-${sys_arch} -o clusterctl" retry 5 ${cmnd} @@ -156,7 +145,6 @@ install_capi-config() { } init() { - install_wget install_nats-logger install_capi-config install_helm diff --git a/providers/aws/Dockerfile b/providers/aws/Dockerfile deleted file mode 100644 index 4c6f614..0000000 --- a/providers/aws/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM ubuntu:latest - -ARG TARGETOS -ARG TARGETARCH - -LABEL org.opencontainers.image.source="https://github.com/kluster-api/capi-scripts" - -ENV CLUSTERCTL="v1.6.3" -ENV CLUSTERAWSADM_VERSION="v2.4.2" -ENV INFRASTRUCTURE_VERSION="v2.4.2" -ENV CLUSTER_API_VERSION="v1.6.3" -ENV IAM_AUTHENTICATOR_VERSION="0.6.14" - -RUN apt-get -y update; apt-get -y install curl - -COPY script.sh . - -RUN chmod +x script.sh -RUN ./script.sh \ No newline at end of file diff --git a/providers/azure/Dockerfile b/providers/azure/Dockerfile deleted file mode 100644 index d974f64..0000000 --- a/providers/azure/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM ubuntu:latest - -ARG TARGETOS -ARG TARGETARCH - -LABEL org.opencontainers.image.source="https://github.com/kluster-api/capi-scripts" - -ENV CLUSTERCTL="v1.6.3" -ENV INFRASTRUCTURE_VERSION="v1.14.2" -ENV CLUSTER_API_VERSION="v1.6.3" - -RUN apt-get -y update; apt-get -y install curl - -COPY script.sh . - -RUN chmod +x script.sh -RUN ./script.sh \ No newline at end of file diff --git a/providers/gcp/Dockerfile b/providers/gcp/Dockerfile deleted file mode 100644 index 9495279..0000000 --- a/providers/gcp/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM ubuntu:latest - -ARG TARGETOS -ARG TARGETARCH - -LABEL org.opencontainers.image.source="https://github.com/kluster-api/capi-scripts" - -ENV CLUSTERCTL="v1.6.3" -ENV INFRASTRUCTURE_VERSION="v1.6.0" -ENV CLUSTER_API_VERSION="v1.6.3" -ENV YQ_VERSION="v4.2.0" - -RUN apt-get -y update; apt-get -y install curl - -COPY script.sh . - -RUN chmod +x script.sh -RUN ./script.sh \ No newline at end of file diff --git a/providers/hetzner/Dockerfile b/providers/hetzner/Dockerfile deleted file mode 100644 index f3c05fe..0000000 --- a/providers/hetzner/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM ubuntu:latest - -ARG TARGETOS -ARG TARGETARCH - -LABEL org.opencontainers.image.source="https://github.com/kluster-api/capi-scripts" - -ENV CLUSTERCTL="v1.6.3" - -#for alpine -#RUN apk add --no-cache bash curl ca-certificates - -#for ubuntu -RUN apt-get -y update; apt-get -y install curl - -COPY script.sh . - -RUN chmod +x script.sh -RUN ./script.sh \ No newline at end of file