diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e098dd84b0..a6621b0bf3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,9 +7,14 @@ on: branches: - master +defaults: + run: + shell: bash + jobs: - release: - runs-on: ubuntu-latest + build-binaries: + runs-on: ubuntu-20.04 + name: Build binaries steps: - name: Checkout uses: actions/checkout@v2 @@ -23,29 +28,69 @@ jobs: run: | make build chmod -R +x dist - zip -r release.zip dist + - name: Make checksums + run: make checksums + - name: store artifacts + uses: actions/upload-artifact@v2 + with: + name: binaries + path: dist - - name: Release binaries - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') + build-push-linux-multi: + name: Build & push linux/amd64 and linux/arm64 + needs: [ build-binaries ] + runs-on: ubuntu-20.04 + strategy: + matrix: + target: [ argo-events ] + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Download binaries + uses: actions/download-artifact@v2 with: - files: release.zip - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: binaries + path: dist/ - - name: Docker Login - uses: Azure/docker-login@v1 + - name: Registry Login + uses: docker/login-action@v1 with: - login-server: quay.io + registry: quay.io username: ${{ secrets.QUAYIO_USERNAME }} password: ${{ secrets.QUAYIO_PASSWORD }} - - - name: Build & Push Linux Docker Images - env: - QUAYIO_ORG: ${{ secrets.QUAYIO_ORG }} + + - name: set Version + id: version run: | tag=$(basename $GITHUB_REF) if [ $tag = "master" ]; then tag="latest" fi - make image IMAGE_TAG=${tag} IMAGE_NAMESPACE=${QUAYIO_ORG} DOCKER_PUSH=true + echo "::set-output name=VERSION::$tag" + + - name: Container build and push with arm64/amd64 + run: | + IMAGE_NAMESPACE=quay.io/${{ secrets.QUAYIO_USERNAME }} VERSION=${{ steps.version.outputs.VERSION }} DOCKER_PUSH=true make image-multi + + release: + runs-on: ubuntu-latest + needs: [ build-push-linux-multi ] + steps: + - name: Download binaries + uses: actions/download-artifact@v2 + with: + name: binaries + path: dist/ + + - name: Release binaries + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + dist/*.gz + dist/*.gz.sha256 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 9e5721f6e7..327ea6cf5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,27 @@ +ARG ARCH=$TARGETARCH #################################################################################################### # base #################################################################################################### FROM alpine:3.12.3 as base +ARG ARCH RUN apk update && apk upgrade && \ apk add ca-certificates && \ apk --no-cache add tzdata ENV ARGO_VERSION=v3.0.2 -RUN wget -q https://github.com/argoproj/argo/releases/download/${ARGO_VERSION}/argo-linux-amd64.gz -RUN gunzip argo-linux-amd64.gz -RUN chmod +x argo-linux-amd64 -RUN mv ./argo-linux-amd64 /usr/local/bin/argo -RUN argo version +RUN wget -q https://github.com/argoproj/argo/releases/download/${ARGO_VERSION}/argo-linux-${ARCH}.gz +RUN gunzip -f argo-linux-${ARCH}.gz +RUN chmod +x argo-linux-${ARCH} +RUN mv ./argo-linux-${ARCH} /usr/local/bin/argo #################################################################################################### # argo-events #################################################################################################### FROM scratch as argo-events +ARG ARCH COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=base /usr/local/bin/argo /usr/local/bin/argo -COPY dist/argo-events /bin/argo-events +COPY dist/argo-events-linux-${ARCH} /bin/argo-events ENTRYPOINT [ "/bin/argo-events" ] - diff --git a/Makefile b/Makefile index 59121b93e7..aab3b53a0c 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ GIT_COMMIT=$(shell git rev-parse HEAD) GIT_BRANCH=$(shell git rev-parse --symbolic-full-name --verify --quiet --abbrev-ref HEAD) GIT_TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact-match --tags HEAD 2>/dev/null; fi) GIT_TREE_STATE=$(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi) +BUILDX_BINARY_URL="https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64" +EXECUTABLES = curl docker gzip go # docker image publishing options DOCKER_PUSH?=false @@ -25,6 +27,7 @@ override LDFLAGS += \ -X ${PACKAGE}.gitTreeState=${GIT_TREE_STATE} ifeq (${DOCKER_PUSH},true) +PUSH_OPTION="--push" ifndef IMAGE_NAMESPACE $(error IMAGE_NAMESPACE must be set to push images (e.g. IMAGE_NAMESPACE=quay.io/argoproj)) endif @@ -35,15 +38,22 @@ VERSION=$(GIT_TAG) override LDFLAGS += -X ${PACKAGE}.gitTag=${GIT_TAG} endif +# Check that the needed executables are available, else exit before the build +K := $(foreach exec,$(EXECUTABLES), $(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH"))) + .PHONY: build image clean test # build .PHONY: build -build: dist/$(BINARY_NAME)-linux-amd64 +build: dist/$(BINARY_NAME)-linux-amd64.gz dist/$(BINARY_NAME)-linux-arm64.gz dist/$(BINARY_NAME)-linux-arm.gz dist/$(BINARY_NAME)-linux-ppc64le.gz dist/$(BINARY_NAME)-linux-s390x.gz + +dist/$(BINARY_NAME)-%.gz: dist/$(BINARY_NAME)-% + @[ -e dist/$(BINARY_NAME)-$*.gz ] || gzip -k dist/$(BINARY_NAME)-$* dist/$(BINARY_NAME): GOARGS = GOOS= GOARCH= dist/$(BINARY_NAME)-linux-amd64: GOARGS = GOOS=linux GOARCH=amd64 dist/$(BINARY_NAME)-linux-arm64: GOARGS = GOOS=linux GOARCH=arm64 +dist/$(BINARY_NAME)-linux-arm: GOARGS = GOOS=linux GOARCH=arm dist/$(BINARY_NAME)-linux-ppc64le: GOARGS = GOOS=linux GOARCH=ppc64le dist/$(BINARY_NAME)-linux-s390x: GOARGS = GOOS=linux GOARCH=s390x @@ -51,13 +61,24 @@ dist/$(BINARY_NAME): go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/$(BINARY_NAME) ./cmd dist/$(BINARY_NAME)-%: - CGO_ENABLED=0 $(GOARGS) go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/$(BINARY_NAME) ./cmd + CGO_ENABLED=0 $(GOARGS) go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/$(BINARY_NAME)-$* ./cmd .PHONY: build image: dist/$(BINARY_NAME)-linux-amd64 - DOCKER_BUILDKIT=1 docker build -t $(IMAGE_NAMESPACE)/$(BINARY_NAME):$(VERSION) --target argo-events -f $(DOCKERFILE) . + DOCKER_BUILDKIT=1 docker build -t $(IMAGE_NAMESPACE)/$(BINARY_NAME):$(VERSION) --target $(BINARY_NAME) -f $(DOCKERFILE) . @if [ "$(DOCKER_PUSH)" = "true" ]; then docker push $(IMAGE_NAMESPACE)/$(BINARY_NAME):$(VERSION); fi +image-linux-%: dist/$(BINARY_NAME)-linux-$* + DOCKER_BUILDKIT=1 docker build --build-arg "ARCH=$*" -t $(IMAGE_NAMESPACE)/$(BINARY_NAME):$(VERSION)-linux-$* --platform "linux/$*" --target $(BINARY_NAME) -f $(DOCKERFILE) . + @if [ "$(DOCKER_PUSH)" = "true" ]; then docker push $(IMAGE_NAMESPACE)/$(BINARY_NAME):$(VERSION)-linux-$*; fi + +image-multi: set-qemu dist/$(BINARY_NAME)-linux-arm64.gz dist/$(BINARY_NAME)-linux-amd64.gz + docker buildx build --tag $(IMAGE_NAMESPACE)/$(BINARY_NAME):$(VERSION) --target $(BINARY_NAME) --platform linux/amd64,linux/arm64 --file ./Dockerfile ${PUSH_OPTION} . + +set-qemu: + docker pull tonistiigi/binfmt:latest + docker run --rm --privileged tonistiigi/binfmt:latest --install amd64,arm64 + test: go test $(shell go list ./... | grep -v /vendor/ | grep -v /test/e2e/) -race -short -v @@ -149,3 +170,6 @@ update-manifests-version: cat Makefile | sed 's/^VERSION?=.*/VERSION?=$(VERSION)/' | sed 's/^BASE_VERSION:=.*/BASE_VERSION:=$(VERSION)/' > /tmp/ae_makefile mv /tmp/ae_makefile Makefile +.PHONY: checksums +checksums: + for f in ./dist/$(BINARY_NAME)-*.gz; do openssl dgst -sha256 "$$f" | awk ' { print $$2 }' > "$$f".sha256 ; done