Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action with multi-CPU architecture support and multi docker file support. #5

Merged
merged 14 commits into from
Aug 3, 2020
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/.idea
/*.iml

/.dev
/.git
/.github
/.res
/bin
/dist
/doc
/vendor
/.gitattributes
/.gitignore
/CHANGELOG.md
/README.md
127 changes: 127 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: build

on:
push:
branches:
- 'master'
- 'v*'
tags:
- 'v*'
paths-ignore:
- '**.md'
pull_request:
branches:
- 'master'
- 'v*'
paths-ignore:
- '**.md'

jobs:

go:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Prepare
id: prepare
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo ::set-output name=tag_name::${GITHUB_REF#refs/tags/}
fi
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.13
-
name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Go mod
run: go mod download
-
name: Go test
run: go test -v ./...
docker:
runs-on: ubuntu-18.04
needs: go
steps:
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Prepare
id: prepare
run: |
DOCKER_USERNAME=${{secrets.DOCKER_USERNAME}}
DOCKER_IMAGE=${{secrets.DOCKER_IMAGE}}
DOCKER_REPO=${{secrets.DOCKER_REPO}}
DOCKER_PLATFORMS=linux/amd64,linux/s390x
VERSION=latest

if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi

TAGS="--tag ${DOCKER_IMAGE}:${VERSION}"
TAGS_RHEL="--tag ${DOCKER_IMAGE}:${VERSION}-rhel"

echo ::set-output name=docker_username::${DOCKER_USERNAME}
echo ::set-output name=docker_repo::${DOCKER_REPO}
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS} --file build/dockerfiles/Dockerfile .

echo ::set-output name=buildx_args_rhel::--platform linux/amd64 \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS_RHEL} --file build/dockerfiles/rhel.Dockerfile .
-
name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3.2.0
with:
buildx-version: v0.4.1
-
name: Docker Buildx (build)
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
-
name: Docker Login
if: success() && github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/'))
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login ${{ steps.prepare.outputs.docker_repo }} --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin
-
name: Docker Buildx (push)
if: success() && github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/'))
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }}
-
name: Docker Buildx rhel (push)
if: success() && github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/'))
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args_rhel }}
-
name: Docker Check Manifest
if: success() && github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/'))
run: |
docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
-
name: Clear
if: always() && github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/'))
run: |
rm -f ${HOME}/.docker/config.json
51 changes: 0 additions & 51 deletions .github/workflows/ci.yaml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/pr.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

/.idea
/*.iml
# Dependency directories (remove the comment below to include it)
# vendor/
80 changes: 64 additions & 16 deletions build/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,71 @@
# Red Hat, Inc. - initial API and implementation
#

FROM golang:1.13-alpine3.12 as builder
ENV CGO_ENABLED=0
ENV GOOS=linux
RUN apk add --no-cache ca-certificates
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13-alpine3.12 as builder

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN printf "I am running on ${BUILDPLATFORM:-linux/amd64}, building for ${TARGETPLATFORM:-linux/amd64}\n$(uname -a)\n" \
&& $(case ${TARGETPLATFORM:-linux/amd64} in \
"linux/amd64") echo "GOOS=linux GOARCH=amd64" > /tmp/.env ;; \
"linux/s390x") echo "GOOS=linux GOARCH=s390x" > /tmp/.env ;; \
*) echo "TARGETPLATFORM ${TARGETPLATFORM} not found..." && exit 1 ;; \
esac) \
&& cat /tmp/.env
RUN env $(cat /tmp/.env | xargs) go env

RUN apk --update --no-cache add \
build-base \
gcc \
git \
&& rm -rf /tmp/* /var/cache/apk/*
RUN adduser -D -g '' appuser
WORKDIR /go/src/github.com/che-incubator/configbump
# copy go.mod go.sum
COPY go.mod go.sum ./
# Get dependancies - will also be cached if we won't change mod/sum
RUN go mod download && go mod verify
COPY . /go/src/github.com/che-incubator/configbump
RUN go test -v ./...
RUN go build -a -ldflags '-w -s' -a -installsuffix cgo -o configbump cmd/configbump/main.go

FROM alpine:3.12
WORKDIR /app

ENV GO111MODULE on
ENV GOPROXY https://goproxy.io
COPY go.mod .
COPY go.sum .
RUN env $(cat /tmp/.env | xargs) go mod download
COPY . ./

ARG VERSION=dev
RUN env $(cat /tmp/.env | xargs) go build -a -ldflags '-w -s' -a -installsuffix cgo -o configbump cmd/configbump/main.go

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

LABEL maintainer="Eclispe Che team" \
skabashnyuk marked this conversation as resolved.
Show resolved Hide resolved
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.url="https://github.com/che-incubator/configbump" \
org.opencontainers.image.source="https://github.com/che-incubator/configbump" \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.vendor="Eclispe Che team" \
skabashnyuk marked this conversation as resolved.
Show resolved Hide resolved
org.opencontainers.image.title="ConfigBump" \
org.opencontainers.image.description="This is a simple Kubernetes controller that is able to quickly synchronize a set of configmaps (selected using labels) to files on local filesystem." \
org.opencontainers.image.licenses="EPL 2.0"

ENV EDITION_IDS="ConfigBump"

RUN apk --update --no-cache add \
ca-certificates \
libressl \
tzdata \
&& rm -rf /tmp/* /var/cache/apk/*

USER appuser
COPY --from=builder /app/configbump /usr/local/bin/configbump
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/src/github.com/che-incubator/configbump/configbump /usr/local/bin
ENTRYPOINT ["configbump"]
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip /usr/local/go/lib/time/zoneinfo.zip

ENTRYPOINT [ "/usr/local/bin/configbump" ]