diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..20f193d8f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,120 @@ +on: + release: + types: [created] +name: Handle Release +jobs: + builder: + name: Generate builder containers + runs-on: ubuntu-20.04 + steps: + - name: Checkout the repository + uses: actions/checkout@master + - name: Set the environment variables + run: | + echo "GOLANG_VERSION=$(grep -m 1 GOLANG_VERSION Makefile | sed 's/^.*= //g')" >> $GITHUB_ENV + echo "ALPINE_VERSION=$(grep -m 1 ALPINE_VERSION Makefile | sed 's/^.*= //g')" >> $GITHUB_ENV + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + krakend/builder + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + - name: Docker meta + id: meta-linux-generic + uses: docker/metadata-action@v4 + with: + images: | + krakend/builder + flavor: | + suffix=-linux-generic,onlatest=true + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + - name: Build and push KrakenD plugin builder (Alpine) + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile-builder + build-args: | + GOLANG_VERSION=${{ env.GOLANG_VERSION }} + ALPINE_VERSION=${{ env.ALPINE_VERSION }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Build and push KrakenD plugin builder (Linux generic) + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile-builder-linux + build-args: | + GOLANG_VERSION=${{ env.GOLANG_VERSION }} + push: true + tags: ${{ steps.meta-linux-generic.outputs.tags }} + labels: ${{ steps.meta-linux-generic.outputs.labels }} + generate: + name: Create release-artifacts + runs-on: ubuntu-20.04 + needs: builder + steps: + - name: Checkout the repository + uses: actions/checkout@master + - name: Import GPG key + id: import_gpg + uses: crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.PGP_SIGNING_KEY }} + fingerprint: "5B270F2E01E375FD9D5635E25DE6FD698AD6FDD2" + - name: List keys + run: gpg -K + - name: Generate the artifacts for Debian/Ubuntu/Redhat/Centos (AMD64/ARM64) + uses: docker://krakend/builder:latest-linux-generic + with: + args: sh -c "export CC=aarch64-linux-gnu-gcc ARCH=arm64 OS_TAG=_generic-linux GOARCH=arm64 GOHOSTARCH=amd64 EXTRA_LDFLAGS='-extld=aarch64-linux-gnu-gcc'; + make -e build && make -e tgz; + make clean; + export CC= GOARCH=amd64 ARCH=amd64 OS_TAG=_generic-linux EXTRA_LDFLAGS=; + make -e build && make -e tgz;" + - name: Build DEB package (AMD64) + uses: docker://krakend/fpm:deb + with: + entrypoint: /bin/bash + args: -c "make -e deb-release" + - name: Build RPM package (AMD64) + uses: docker://krakend/fpm:rpm + with: + entrypoint: /bin/bash + args: -c "echo '${{ secrets.PGP_SIGNING_KEY }}' > pgp.key; + gpg --import pgp.key; + cp builder/files/rpmmacros /etc/rpm/macros; + make -e rpm-release && + rpmsign --addsign *rpm" + - name: Generate the artifacts for Alpine (AMD64/ARM64) + uses: docker://krakend/builder:latest + with: + args: sh -c "export GOARCH=amd64 ARCH=amd64 OS_TAG=_alpine; + make -e build && make -e tgz; + make clean; + export ARCH=arm64 OS_TAG=_alpine GOARCH=arm64 GOHOSTARCH=amd64; + export CC=aarch64-linux-musl-gcc EXTRA_LDFLAGS='-extld=aarch64-linux-musl-gcc'; + make -e build && make -e tgz" + - name: ASC files + run: for i in $(ls *.tar.gz *.deb *.rpm); + do gpg --armor --detach $i; + sha512sum $i >> checksums.txt; + done + - name: Upload the artifacts + uses: skx/github-action-publish-binaries@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: '*.tar.gz *.asc *.deb *.rpm checksums.txt' diff --git a/Dockerfile b/Dockerfile index 191db2295..80cf97acb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ FROM alpine:${ALPINE_VERSION} LABEL maintainer="community@krakend.io" -RUN apk add --no-cache ca-certificates && \ +RUN apk add --no-cache ca-certificates tzdata && \ adduser -u 1000 -S -D -H krakend && \ mkdir /etc/krakend && \ echo '{ "version": 3 }' > /etc/krakend/krakend.json diff --git a/Dockerfile-builder b/Dockerfile-builder new file mode 100644 index 000000000..7429c22fe --- /dev/null +++ b/Dockerfile-builder @@ -0,0 +1,10 @@ +ARG GOLANG_VERSION +ARG ALPINE_VERSION +FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} + +RUN apk --no-cache --virtual .build-deps add tar make gcc musl-dev binutils-gold + +RUN cd / && wget http://musl.cc/aarch64-linux-musl-cross.tgz && \ + tar zxf aarch64-linux-musl-cross.tgz && rm -f aarch64-linux-musl-cross.tgz + +ENV PATH="$PATH:/aarch64-linux-musl-cross/bin" diff --git a/Dockerfile-builder-linux b/Dockerfile-builder-linux new file mode 100644 index 000000000..dd259af41 --- /dev/null +++ b/Dockerfile-builder-linux @@ -0,0 +1,6 @@ +ARG GOLANG_VERSION +FROM golang:${GOLANG_VERSION} + +RUN apt-get update && \ + apt-get install -y gcc make gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu \ + && rm -rf /var/lib/apt/lists/* diff --git a/Dockerfile-plugin-builder b/Dockerfile-plugin-builder deleted file mode 100644 index 38be8a073..000000000 --- a/Dockerfile-plugin-builder +++ /dev/null @@ -1,5 +0,0 @@ -ARG GOLANG_VERSION -ARG ALPINE_VERSION -FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} - -RUN apk --no-cache --virtual .build-deps add make gcc musl-dev binutils-gold diff --git a/Makefile b/Makefile index 13e47bada..c1a1dd1a1 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,8 @@ DOCKER_FPM := devopsfaith/fpm GOLANG_VERSION := 1.19.2 GLIBC_VERSION := $(shell sh find_glibc.sh) ALPINE_VERSION := 3.16 +OS_TAG := +EXTRA_LDFLAGS := FPM_OPTS=-s dir -v $(VERSION) -n $(PKGNAME) \ --license "$(LICENSE)" \ @@ -48,9 +50,6 @@ RPM_OPTS =--rpm-user $(USER) \ --before-remove builder/scripts/prerm.rpm \ --after-remove builder/scripts/postrm.rpm -DEBNAME=${PKGNAME}_${VERSION}-${RELEASE}_${ARCH}.deb -RPMNAME=${PKGNAME}-${VERSION}-${RELEASE}.x86_64.rpm - all: test build: @@ -58,7 +57,7 @@ build: @go get . @go build -ldflags="-X github.com/luraproject/lura/v2/core.KrakendVersion=${VERSION} \ -X github.com/luraproject/lura/v2/core.GoVersion=${GOLANG_VERSION} \ - -X github.com/luraproject/lura/v2/core.GlibcVersion=${GLIBC_VERSION}" \ + -X github.com/luraproject/lura/v2/core.GlibcVersion=${GLIBC_VERSION} ${EXTRA_LDFLAGS}" \ -o ${BIN_NAME} ./cmd/krakend-ce @echo "You can now use ./${BIN_NAME}" @@ -66,15 +65,18 @@ test: build go test -v ./tests # Build KrakenD using docker (defaults to whatever the golang container uses) -build_on_docker: - docker run --rm -it -v "${PWD}:/app" -w /app golang:${GOLANG_VERSION} make -e build +build_on_docker: docker-builder-linux + docker run --rm -it -v "${PWD}:/app" -w /app krakend/builder:${VERSION}-linux-generic make -e build # Build the container using the Dockerfile (alpine) docker: docker build --no-cache --pull --build-arg GOLANG_VERSION=${GOLANG_VERSION} --build-arg ALPINE_VERSION=${ALPINE_VERSION} -t devopsfaith/krakend:${VERSION} . -docker-plugin-builder: - docker build --no-cache --pull --build-arg GOLANG_VERSION=${GOLANG_VERSION} --build-arg ALPINE_VERSION=${ALPINE_VERSION} -t devopsfaith/krakend-plugin-builder:${VERSION} -f Dockerfile-plugin-builder . +docker-builder: + docker build --no-cache --pull --build-arg GOLANG_VERSION=${GOLANG_VERSION} --build-arg ALPINE_VERSION=${ALPINE_VERSION} -t krakend/builder:${VERSION} -f Dockerfile-builder . + +docker-builder-linux: + docker build --no-cache --pull --build-arg GOLANG_VERSION=${GOLANG_VERSION} -t krakend/builder:${VERSION}-linux-generic -f Dockerfile-builder-linux . benchmark: @mkdir -p bench_res @@ -126,7 +128,7 @@ builder/skel/%/etc/logrotate.d/krakend: builder/files/krakend-logrotate tgz: builder/skel/tgz/usr/bin/krakend tgz: builder/skel/tgz/etc/krakend/krakend.json tgz: builder/skel/tgz/etc/init.d/krakend - tar zcvf krakend_${VERSION}_${ARCH}.tar.gz -C builder/skel/tgz/ . + tar zcvf krakend_${VERSION}_${ARCH}${OS_TAG}.tar.gz -C builder/skel/tgz/ . .PHONY: deb deb: builder/skel/deb/usr/bin/krakend @@ -150,12 +152,26 @@ rpm: builder/skel/rpm/etc/logrotate.d/krakend -C builder/skel/rpm \ ${FPM_OPTS} +.PHONY: deb-release +deb-release: builder/skel/deb-release/usr/bin/krakend +deb-release: builder/skel/deb-release/etc/krakend/krakend.json + /usr/local/bin/fpm -t deb ${DEB_OPTS} \ + --iteration ${RELEASE} \ + --deb-systemd builder/files/krakend.service \ + -C builder/skel/deb-release \ + ${FPM_OPTS} + +.PHONY: rpm-release +rpm-release: builder/skel/rpm-release/usr/lib/systemd/system/krakend.service +rpm-release: builder/skel/rpm-release/usr/bin/krakend +rpm-release: builder/skel/rpm-release/etc/krakend/krakend.json + /usr/local/bin/fpm -t rpm ${RPM_OPTS} \ + --iteration ${RELEASE} \ + -C builder/skel/rpm-release \ + ${FPM_OPTS} .PHONY: clean clean: rm -rf builder/skel/* - rm -f *.deb - rm -f *.rpm - rm -f *.tar.gz rm -f krakend rm -rf vendor/ diff --git a/builder/files/rpmmacros b/builder/files/rpmmacros new file mode 100644 index 000000000..10fff5ab9 --- /dev/null +++ b/builder/files/rpmmacros @@ -0,0 +1 @@ +%_gpg_name 5DE6FD698AD6FDD2 \ No newline at end of file