From baa5bd9410c6a49a9c39e9c3db6b7fea4131c1ea Mon Sep 17 00:00:00 2001 From: sam-at-luther Date: Wed, 5 Jul 2023 16:05:04 -0700 Subject: [PATCH 1/3] Add docker release --- .../actions/build-docker-images/action.yml | 38 +++++++++++ .../actions/configure-dockerhub/action.yml | 10 +++ .github/workflows/pushproxng-ci.yml | 30 ++++++--- .github/workflows/pushproxng-release.yml | 42 +++++++++++++ .gitignore | 1 + Dockerfile | 5 ++ Makefile | 63 +++++++++++++++++-- common.mk | 4 -- proxy/.gitignore | 1 + 9 files changed, 176 insertions(+), 18 deletions(-) create mode 100644 .github/actions/build-docker-images/action.yml create mode 100644 .github/actions/configure-dockerhub/action.yml create mode 100644 .github/workflows/pushproxng-release.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 proxy/.gitignore diff --git a/.github/actions/build-docker-images/action.yml b/.github/actions/build-docker-images/action.yml new file mode 100644 index 0000000..91d23eb --- /dev/null +++ b/.github/actions/build-docker-images/action.yml @@ -0,0 +1,38 @@ +name: Build Docker Images +description: A custom action to build Docker images for specified platforms and images +inputs: + arch: + description: The platform architecture + required: true + image: + description: The image to build + required: true + git_tag: + description: Git release tag + default: '' + git_rev: + description: Git commit hash + default: '' + +runs: + using: composite + steps: + - name: Checkout Repository + uses: actions/checkout@v3.5.0 + + - name: Configure DockerHub + uses: ./.github/actions/configure-dockerhub + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + platforms: linux/${{ inputs.arch }} + + - name: Build docker image for ${{ inputs.arch }} + shell: bash + run: | + TARGET="" + if [[ -n "${{ inputs.git_tag }}" ]]; then + TARGET="push" + fi + cd ${{ inputs.image }} && make PLATFORMS=linux/${{ inputs.arch }} TAG_SUFFIX=-${{ inputs.arch }} GIT_TAG=${{ inputs.git_tag }} GIT_REVISION=${{ inputs.git_rev }} $TARGET diff --git a/.github/actions/configure-dockerhub/action.yml b/.github/actions/configure-dockerhub/action.yml new file mode 100644 index 0000000..abeb15c --- /dev/null +++ b/.github/actions/configure-dockerhub/action.yml @@ -0,0 +1,10 @@ +name: configure-dockerhub +runs: + using: composite + steps: + - name: Configure Docker Hub + run: |- + [ -z "$DOCKERHUB_USERNAME" ] && exit 0 + [ -z "$DOCKERHUB_TOKEN" ] && exit 0 + docker login --username $DOCKERHUB_USERNAME --password=$DOCKERHUB_TOKEN + shell: bash \ No newline at end of file diff --git a/.github/workflows/pushproxng-ci.yml b/.github/workflows/pushproxng-ci.yml index 8504830..8054a2a 100644 --- a/.github/workflows/pushproxng-ci.yml +++ b/.github/workflows/pushproxng-ci.yml @@ -1,15 +1,29 @@ -name: CI Test +name: CI Build on: pull_request: branches: - main jobs: - test: - runs-on: ubuntu-latest - container: - image: luthersystems/build-go:v0.0.68 + build: + name: ${{ matrix.image }} - ${{ matrix.arch }} docker build + runs-on: ${{ fromJSON('{"arm64":"buildjet-2vcpu-ubuntu-2204-arm","amd64":"ubuntu-20.04"}')[matrix.arch] }} + strategy: + matrix: + arch: + - amd64 + - arm64 + image: + - pushprox steps: - - uses: actions/checkout@v3.5.0 - - name: Run CI - run: make citest + - uses: actions/checkout@v3.5.0 + with: + fetch-depth: 0 # include tags for VERSION detection + - name: Run CI + run: make citest + - name: Build container + uses: ./.github/actions/build-docker-images + with: + arch: ${{ matrix.arch }} + image: . + git_rev: $GITHUB_SHA diff --git a/.github/workflows/pushproxng-release.yml b/.github/workflows/pushproxng-release.yml new file mode 100644 index 0000000..86b466c --- /dev/null +++ b/.github/workflows/pushproxng-release.yml @@ -0,0 +1,42 @@ +name: Build Release and Push +on: + push: + tags: + - '*' +env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }} +jobs: + build-push: + name: ${{ matrix.image }} - ${{ matrix.arch }} docker build + runs-on: ${{ fromJSON('{"arm64":"buildjet-2vcpu-ubuntu-2204-arm","amd64":"ubuntu-20.04"}')[matrix.arch] }} + strategy: + matrix: + arch: + - amd64 + - arm64 + image: + - pushprox + steps: + - uses: actions/checkout@v3.5.0 + with: + fetch-depth: 0 # include tags for VERSION detection + - name: Build container + uses: ./.github/actions/build-docker-images + with: + arch: ${{ matrix.arch }} + image: . + git_tag: $GITHUB_REF_NAME + push-manifests: + runs-on: ubuntu-20.04 + needs: + - build-push + steps: + - name: Checkout Repository + uses: actions/checkout@v3.5.0 + - name: Configure DockerHub + uses: ./.github/actions/configure-dockerhub + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Create and push manifest for multiarch + run: make push-manifests GIT_TAG=$GITHUB_REF_NAME diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6a944e7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM golang:alpine +COPY build/proxy /opt/ +WORKDIR /opt +ENTRYPOINT [ "/opt/proxy" ] +CMD [ "--listen=:8080" ] diff --git a/Makefile b/Makefile index 683a3f0..81b9903 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ -PROJECT_REL_DIR=./ -include ${PROJECT_REL_DIR}/common.mk -DOCKER_PROJECT_DIR:=$(call DOCKER_DIR, ${PROJECT_REL_DIR}) +include common.mk +STATIC_IMAGE=luthersystems/pushprox -.PHONY: default -default: all +STATIC_IMAGE_DUMMY=${call IMAGE_DUMMY,${STATIC_IMAGE}/${VERSION}} + +HWTYPE=$(shell uname -m) +LOCALARCH=$(if $(findstring ${HWTYPE},"x86_64"),amd64,${HWTYPE}) -.PHONY: all +.PHONY: default +default: static .PHONY: static-checks static-checks: @@ -15,6 +17,55 @@ static-checks: go-test: ${GO_TEST_TIMEOUT_10} ./... +proxy/proxy: + GOOS=linux go build -tags netgo -ldflags '-w -extldflags "-static"' -o ./build/proxy ./proxy + +.PHONY: clean +clean: + rm -rf build + rm -fr proxy/proxy + .PHONY: citest citest: static-checks go-test @ + +.PHONY: static +static: ${STATIC_IMAGE_DUMMY} + @ + +.PHONY: push +push: ${FQ_STATIC_IMAGE_DUMMY} + @ + +build-%: LOADARG=$(ifpushprox$(findstring $*,${LOCALARCH}),--load) +build-%: Dockerfile proxy/proxy + ${DOCKER} buildx build \ + --platform linux/$* \ + ${LOADARG} \ + -t ${STATIC_IMAGE}:${VERSION} \ + . + +${STATIC_IMAGE_DUMMY}: + make build-${LOCALARCH} + ${MKDIR_P} $(dir $@) + ${TOUCH} $@ + +${FQ_STATIC_IMAGE_DUMMY}: ${STATIC_IMAGE_DUMMY} + ${DOCKER} tag ${STATIC_IMAGE}:${VERSION} ${FQ_STATIC_IMAGE}:${BUILD_VERSION} + ${DOCKER} push ${FQ_STATIC_IMAGE}:${BUILD_VERSION} + ${MKDIR_P} $(dir $@) + ${TOUCH} $@ + +.PHONY: push-manifests +push-manifests: ${FQ_MANIFEST_DUMMY} + @ + +${FQ_MANIFEST_DUMMY}: + ${DOCKER} buildx imagetools create \ + --tag ${FQ_STATIC_IMAGE}:latest \ + ${FQ_STATIC_IMAGE}:${VERSION}-arm64 \ + ${FQ_STATIC_IMAGE}:${VERSION}-amd64 + ${DOCKER} buildx imagetools create \ + --tag ${FQ_STATIC_IMAGE}:${VERSION} \ + ${FQ_STATIC_IMAGE}:${VERSION}-arm64 \ + ${FQ_STATIC_IMAGE}:${VERSION}-amd64 diff --git a/common.mk b/common.mk index d8b6646..8191b6b 100644 --- a/common.mk +++ b/common.mk @@ -10,10 +10,6 @@ GIT_REVISION ?= $(shell git rev-parse --short HEAD) VERSION ?= $(if $(strip $(GIT_TAG)),$(GIT_TAG),$(GIT_REVISION)) BUILD_VERSION ?= ${VERSION}${TAG_SUFFIX} -GO_PKG_VOLUME=${PROJECT}-build-gopath-pkg -GO_PKG_PATH=/go/pkg -GO_PKG_MOUNT=$(if $(CI),-v $(PWD)/build/pkg:${GO_PKG_PATH},--mount='type=volume,source=${GO_PKG_VOLUME},destination=${GO_PKG_PATH}') - GO_TEST_BASE=go test ${GO_TEST_FLAGS} GO_TEST_TIMEOUT_10=${GO_TEST_BASE} -timeout 10m diff --git a/proxy/.gitignore b/proxy/.gitignore new file mode 100644 index 0000000..125f526 --- /dev/null +++ b/proxy/.gitignore @@ -0,0 +1 @@ +proxy From 2107c83614df6076391b34879c10700406215d51 Mon Sep 17 00:00:00 2001 From: sam-at-luther Date: Wed, 5 Jul 2023 16:08:07 -0700 Subject: [PATCH 2/3] Use build-go --- .github/workflows/pushproxng-ci.yml | 2 ++ .github/workflows/pushproxng-release.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/pushproxng-ci.yml b/.github/workflows/pushproxng-ci.yml index 8054a2a..582308e 100644 --- a/.github/workflows/pushproxng-ci.yml +++ b/.github/workflows/pushproxng-ci.yml @@ -8,6 +8,8 @@ jobs: build: name: ${{ matrix.image }} - ${{ matrix.arch }} docker build runs-on: ${{ fromJSON('{"arm64":"buildjet-2vcpu-ubuntu-2204-arm","amd64":"ubuntu-20.04"}')[matrix.arch] }} + container: + image: luthersystems/build-go:v0.0.68 strategy: matrix: arch: diff --git a/.github/workflows/pushproxng-release.yml b/.github/workflows/pushproxng-release.yml index 86b466c..3352fda 100644 --- a/.github/workflows/pushproxng-release.yml +++ b/.github/workflows/pushproxng-release.yml @@ -10,6 +10,8 @@ jobs: build-push: name: ${{ matrix.image }} - ${{ matrix.arch }} docker build runs-on: ${{ fromJSON('{"arm64":"buildjet-2vcpu-ubuntu-2204-arm","amd64":"ubuntu-20.04"}')[matrix.arch] }} + container: + image: luthersystems/build-go:v0.0.68 strategy: matrix: arch: From a4960382d3e39ed6e6d176802c4abfb14f9b113b Mon Sep 17 00:00:00 2001 From: sam-at-luther Date: Wed, 5 Jul 2023 16:10:07 -0700 Subject: [PATCH 3/3] Remove vcs check --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 81b9903..71fc99c 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ go-test: ${GO_TEST_TIMEOUT_10} ./... proxy/proxy: - GOOS=linux go build -tags netgo -ldflags '-w -extldflags "-static"' -o ./build/proxy ./proxy + GOOS=linux go build -buildvcs=false -tags netgo -ldflags '-w -extldflags "-static"' -o ./build/proxy ./proxy .PHONY: clean clean: