Skip to content

Commit

Permalink
Merge pull request #97 from jihoon-seo/210407-Update-build-and-publis…
Browse files Browse the repository at this point in the history
…h-workflows

Update build and publish workflows
  • Loading branch information
jazmandorf authored Apr 23, 2021
2 parents 0cdbf08 + af5b827 commit d14c88f
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 78 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build-amd64-container-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will build the container image for amd64 arch. (as a basic build test)
name: Build amd64 container image

on:
# On pull-request event with detailed condition below.
pull_request:
branches:
- master
paths-ignore:
- '**.md'
- '.all-contributorsrc'
- '.gitignore'
- 'LICENSE'
- 'CODEOWNERS'

jobs:
# The job key is "building"
building:
# Job name is "Building"
name: Building

# This job runs on Ubuntu-latest
runs-on: ubuntu-18.04
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}

steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Build image
env:
# TODO: Change variable to your repository name and image name.
IMAGE_NAME: cb-webtool
run: docker build . --file Dockerfile --tag $IMAGE_NAME
77 changes: 0 additions & 77 deletions .github/workflows/docker-publish.yml

This file was deleted.

114 changes: 114 additions & 0 deletions .github/workflows/publish-multi-arch-container-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# This workflow will build the container image and publish it to container registries.
name: Publish multi-arch container images

# When its time to do a release do a full cross platform build for all supported
# architectures and push all of them to Docker Hub and GitHub Container Registry (GHCR).
# Only trigger on semver shaped tags.
on:
# "Build and publish" on merged
# Actually, there's no "merged" event.
# A "push" event is occurred after the pull request "close" event with "merged" true condition.
# The "push" event could replace "merged" event.
push:
branches:
- master
tags:
- "v*.*.*"
paths-ignore:
- '**.md'
- '.all-contributorsrc'
- '.gitignore'
- 'LICENSE'
- 'CODEOWNERS'

jobs:
# The job key is "publishing"
publishing:
# Job name is "Publishing"
name: Publishing

# This job runs on Ubuntu-latest
runs-on: ubuntu-18.04

steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Prepare tags
id: prep
env:
# TODO: Change variable to your repository name and image name.
DOCKER_REPO: cloudbaristaorg
IMAGE_NAME: cb-webtool
run: |
VERSION=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
DOCKER_IMAGE=$DOCKER_REPO/$IMAGE_NAME
DOCKER_TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}.*$ ]]; then
DOCKER_TAGS="$DOCKER_TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=docker-tags::${DOCKER_TAGS}
echo ${DOCKER_TAGS}
GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
GHCR_TAGS="${GHCR_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}.*$ ]]; then
GHCR_TAGS="$GHCR_TAGS,${GHCR_IMAGE}:latest"
fi
echo ::set-output name=ghcr-tags::${GHCR_TAGS}
echo ${GHCR_TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- name: Build and publish
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
file: ./Dockerfile
target: prod
platforms: linux/amd64 # linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x,linux/arm/v6
push: true
tags: |
${{ steps.prep.outputs.docker-tags }}
${{ steps.prep.outputs.ghcr-tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11.2-alpine
FROM golang:1.11.2-alpine as prod

WORKDIR /go/src/github.com/cloud-barista/cb-webtool
COPY . .
Expand Down

0 comments on commit d14c88f

Please sign in to comment.