Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
Use buildx and github actions
Browse files Browse the repository at this point in the history
**What**
- Update the Dockerfile to support multiarch builds via buildx
- Add Github Action workflow for build and test
- Add Github Action workflow to publish the images

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler committed Nov 17, 2020
1 parent 856fbba commit ae0053b
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 182 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: build

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

jobs:
build:
strategy:
matrix:
go-version: [1.13.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Get Owner name
id: get_owner_name
run: echo ::set-output name=OWNER_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print tolower($1)}' | sed -e "s/:refs//")
- name: Get Repository name
id: get_repo_name
run: echo ::set-output name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print tolower($2)}' | sed -e "s/:refs//")
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build x86_64 container into library
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: false
platforms: linux/amd64
target: ship
build-args: |
VERSION=${{ steps.get_tag.outputs.TAG }}
GIT_COMMIT=${{ github.sha }}
REPO_URL=https://github.com/${{ env.USER_REPO }}
load: true
# note that the image tags for build/test need to match the value in the contrib/docker-compose.yml
tags: ghcr.io/openfaas/faas-swarm:latest-dev
- name: Install faas-cli
run: ./contrib/get_tools.sh
- name: Init Swarm
run: docker swarm init
- name: Deploy OpenFaaS
run: cd contrib && docker stack deploy func --compose-file docker-compose.yml
env:
BASIC_AUTH: "false"
- name: Wait for startup to finish
run : sleep 15
- name: Debug service state
run: docker service ps func_faas-swarm func_gateway
- name: Debug service logs
run: docker service logs func_faas-swarm
- name: Debug gateway logs
run: docker service logs func_gateway
- name: Authenticate faas-cli
run: cd contrib && cat ci-auth-pass.txt | faas-cli login --username admin --password-stdin
- name: Deploy function
run: faas-cli deploy --image=functions/alpine:latest --fprocess=cat --name "echo"
- name: Verify deployment
run: ./contrib/ci-verify-fnc-deployment.sh
- name: Test invoke the function
run: faas-cli invoke echo <<< "foobar" | grep "foobar"
- name: Remove the function
run: faas-cli rm echo
- name: Stop test cluster
run: docker stack rm func
- name: Build multi-arch containers for validation only
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
outputs: "type=image,push=false"
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: ghcr.io/openfaas/faas-swarm:${{ github.sha }}

49 changes: 49 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: publish

on:
push:
tags:
- '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@master
with:
fetch-depth: 1
- name: Get tags
id: get_tag
run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
- name: Set Username/Repo and ImagePrefix as ENV vars
run: |
echo "USER_REPO"=$(echo "$GITHUB_REPOSITORY" | awk '{print tolower($1)}' | sed -e "s/:refs//") >> $GITHUB_ENV && \
echo "IMAGE_PREFIX"=$(echo "ghcr.io/$GITHUB_REPOSITORY" | awk '{print tolower($1)}' | sed -e "s/:refs//") >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Github Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push container images
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
target: ship
build-args: |
VERSION=${{ steps.get_tag.outputs.TAG }}
GIT_COMMIT=${{ github.sha }}
REPO_URL=https://github.com/${{ env.USER_REPO }}
push: true
# tag names need to match the repo so that they can be safely pushed, even in forks.
tags: |
${{ env.IMAGE_PREFIX }}:${{ github.sha }}
${{ env.IMAGE_PREFIX }}:${{ steps.get_tag.outputs.TAG }}
${{ env.IMAGE_PREFIX }}:latest
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

52 changes: 34 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
FROM teamserverless/license-check:0.3.6 as license-check
FROM teamserverless/license-check:0.3.9 as license-check

FROM golang:1.13 as build
ARG GO111MODULE=off
ARG CGO_ENABLED=0
COPY --from=license-check /license-check /usr/bin/
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13 as build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

ARG NS
ARG REPO
ARG VERSION="dev"
ARG GIT_COMMIT="000000"

RUN mkdir -p /go/src/github.com/openfaas/faas-swarm/
ENV CGO_ENABLED=0
ENV GO111MODULE=on
ENV GOFLAGS=-mod=vendor

COPY --from=license-check /license-check /usr/bin/

WORKDIR /go/src/github.com/openfaas/faas-swarm

Expand All @@ -15,25 +26,30 @@ RUN license-check -path /go/src/github.com/openfaas/faas-swarm/ --verbose=false

RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")

RUN CGO_ENABLED=$CGO_ENABLED go test $(go list ./... | grep -v /vendor/) -cover
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v ./...

RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \
&& GIT_COMMIT=$(git rev-list -1 HEAD) \
&& CGO_ENABLED=$CGO_ENABLED GOOS=linux go build --ldflags "-s -w \
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go build \
--ldflags "-s -w \
-X github.com/openfaas/faas-swarm/version.GitCommit=${GIT_COMMIT}\
-X github.com/openfaas/faas-swarm/version.Version=${VERSION}" \
-a -installsuffix cgo -o faas-swarm .

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

ARG REPO_URL
# Get automactic ghcr linking via the image source
# https://github.com/opencontainers/image-spec/blob/master/annotations.md#pre-defined-annotation-keys
# https://github.community/t/github-container-registry-link-to-a-repo/130336
LABEL org.label-schema.license="MIT" \
org.label-schema.vcs-url="https://github.com/openfaas/faas-swarm" \
org.label-schema.vcs-type="Git" \
org.label-schema.name="openfaas/faas-swarm" \
org.label-schema.vendor="openfaas" \
org.label-schema.docker.schema-version="1.0"

RUN apk --no-cache add ca-certificates
org.label-schema.vcs-url="$REPO_URL" \
org.label-schema.vcs-type="Git" \
org.label-schema.name="openfaas/faas-swarm" \
org.label-schema.vendor="openfaas" \
org.label-schema.docker.schema-version="1.0" \
org.opencontainers.image.source="$REPO_URL"

RUN apk --no-cache add \
ca-certificates

WORKDIR /root/

Expand Down
45 changes: 0 additions & 45 deletions Dockerfile.arm64

This file was deleted.

45 changes: 0 additions & 45 deletions Dockerfile.armhf

This file was deleted.

Loading

0 comments on commit ae0053b

Please sign in to comment.