Skip to content

Commit

Permalink
Merge pull request #6 from luthersystems/sam-at-luther/Add_release_pi…
Browse files Browse the repository at this point in the history
…peline

Add docker release
  • Loading branch information
sam-at-luther authored Jul 5, 2023
2 parents 409de1c + a496038 commit 9417821
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 16 deletions.
38 changes: 38 additions & 0 deletions .github/actions/build-docker-images/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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
10 changes: 10 additions & 0 deletions .github/actions/configure-dockerhub/action.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 22 additions & 6 deletions .github/workflows/pushproxng-ci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
name: CI Test
name: CI Build

on:
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
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:
- amd64
- arm64
image:
- pushprox
steps:
- uses: actions/[email protected]
- name: Run CI
run: make citest
- uses: actions/[email protected]
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
44 changes: 44 additions & 0 deletions .github/workflows/pushproxng-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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] }}
container:
image: luthersystems/build-go:v0.0.68
strategy:
matrix:
arch:
- amd64
- arm64
image:
- pushprox
steps:
- uses: actions/[email protected]
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/[email protected]
- 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM golang:alpine
COPY build/proxy /opt/
WORKDIR /opt
ENTRYPOINT [ "/opt/proxy" ]
CMD [ "--listen=:8080" ]
63 changes: 57 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -15,6 +17,55 @@ static-checks:
go-test:
${GO_TEST_TIMEOUT_10} ./...

proxy/proxy:
GOOS=linux go build -buildvcs=false -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
4 changes: 0 additions & 4 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
proxy

0 comments on commit 9417821

Please sign in to comment.