Skip to content

Commit

Permalink
ci: change to use GitHub actions
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <[email protected]>
  • Loading branch information
FrankYang0529 authored and innobead committed May 1, 2024
1 parent c4df06c commit d6e758c
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 11 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: build
on:
push:
branches:
- master
- v*
tags:
- v*
pull_request:
jobs:
build:
name: Build binaries
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

# Build binaries
- name: Run ci
run: make ci

- uses: codecov/codecov-action@v4
with:
files: ./coverage.out
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries_artifact
path: ./bin/*

build_push_image:
name: Build and push image
runs-on: ubuntu-latest
needs: build
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries_artifact
path: ./bin/

- name: Add executable permission
run: |
chmod +x ./bin/*
- name: Copy binaries to package
run: |
cp -r ./bin/* ./package/
# For multi-platform support
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Declare branch
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# longhornio/upgrade-responder image
- name: docker-publish
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: package/
push: true
platforms: linux/amd64,linux/arm64
tags: longhornio/upgrade-responder:${{ env.branch }}-head
file: package/Dockerfile

- name: docker-publish-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: package/
push: true
platforms: linux/amd64,linux/arm64
tags: longhornio/upgrade-responder:${{ github.ref_name }}
file: package/Dockerfile
10 changes: 9 additions & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
FROM golang:1.22-alpine

ARG DAPPER_HOST_ARCH
ENV ARCH=${DAPPER_HOST_ARCH}

RUN apk -U add bash git gcc musl-dev docker vim less file curl wget ca-certificates
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

# The docker version in dapper is too old to have buildx. Install it manually.
RUN wget https://github.com/docker/buildx/releases/download/v0.13.1/buildx-v0.13.1.linux-${ARCH} && \
chmod +x buildx-v0.13.1.linux-${ARCH} && \
mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx

ENV DAPPER_ENV REPO TAG DRONE_TAG
ENV DAPPER_SOURCE /go/src/github.com/longhorn/upgrade-responder/
ENV DAPPER_OUTPUT ./bin ./dist ./package
ENV DAPPER_OUTPUT ./bin ./dist ./package coverage.out
ENV DAPPER_DOCKER_SOCKET true
ENV HOME ${DAPPER_SOURCE}
WORKDIR ${DAPPER_SOURCE}
Expand Down
13 changes: 12 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# syntax=docker/dockerfile:1.7.0

FROM ubuntu:20.04

ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi

ENV ARCH ${TARGETPLATFORM#linux/}

COPY GeoLite2-City.mmdb /usr/share/
COPY upgrade-responder /usr/bin/
COPY upgrade-responder-${ARCH} /usr/bin/upgrade-responder
CMD ["upgrade-responder"]
ENV GEODB /usr/share/GeoLite2-City.mmdb
3 changes: 2 additions & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ cd $(dirname $0)/..

mkdir -p bin
[ "$(uname)" != "Darwin" ] && LINKFLAGS="-extldflags -static -s"
CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/upgrade-responder
CGO_ENABLED=0 GOARCH=amd64 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/upgrade-responder-amd64
CGO_ENABLED=0 GOARCH=arm64 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/upgrade-responder-arm64
10 changes: 3 additions & 7 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ set -e

source $(dirname $0)/version

ARCH=${ARCH:-"amd64"}
SUFFIX=""
[ "${ARCH}" != "amd64" ] && SUFFIX="_${ARCH}"

cd $(dirname $0)/../package

TAG=${TAG:-${VERSION}${SUFFIX}}
TAG=${TAG:-${VERSION}}
REPO=${REPO:-longhornio}

if echo $TAG | grep -q dirty; then
TAG=dev
fi

cp ../bin/upgrade-responder .
cp ../bin/upgrade-responder-* .
cp ../geodb/GeoLite2-City.mmdb .

IMAGE=${REPO}/upgrade-responder:${TAG}
docker build -t ${IMAGE} .
buildx build --load -t ${IMAGE} .
echo ${IMAGE} > ../dist/images
echo Built ${IMAGE}
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ echo Running tests
PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')"

[ "${ARCH}" == "amd64" ] && RACE=-race
go test ${RACE} -cover -tags=test ${PACKAGES}
go test ${RACE} -cover -tags=test ${PACKAGES} -coverprofile=coverage.out

0 comments on commit d6e758c

Please sign in to comment.