Skip to content

Commit

Permalink
tooling: build multiarch docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
abemedia committed Aug 14, 2020
1 parent 74ac88e commit efb2d82
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
68 changes: 49 additions & 19 deletions .github/workflows/fider.yml
Expand Up @@ -3,10 +3,10 @@ name: fider
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master

jobs:
test-ui:
Expand All @@ -32,7 +32,7 @@ jobs:
minio:
image: getfider/minio:0.0.2
ports:
- 9000:9000
- 9000:9000
env:
MINIO_ACCESS_KEY: s3user
MINIO_SECRET_KEY: s3user-s3cr3t
Expand All @@ -43,7 +43,7 @@ jobs:
POSTGRES_PASSWORD: fider_ci_pw
POSTGRES_DB: fider_ci
ports:
- 5432:5432
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
Expand All @@ -67,24 +67,54 @@ jobs:

steps:
- name: checkout code
uses: actions/checkout@v1
- run: docker build -t getfider/fider .

- name: extract branch name
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: getBranch
uses: actions/checkout@v2

- name: set up docker buildx
uses: crazy-max/ghaction-docker-buildx@v3

- uses: azure/docker-login@v1
if: steps.getBranch.outputs.branch == 'master'
- name: cache docker layers
uses: actions/cache@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-

- name: build docker image
run: |
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--platform linux/386,linux/amd64,linux/arm64 \
--output "type=image,push=false" \
--tag getfider/fider .
# fails when used with buildx - see https://github.com/crazy-max/ghaction-docker-buildx/issues/230
# TODO: re-enable once issue above is fixed
# - uses: azure/docker-login@v1
# if: github.ref == 'refs/heads/master'
# with:
# username: ${{ secrets.DOCKER_USER }}
# password: ${{ secrets.DOCKER_PASS }}

- name: docker login
if: github.ref == 'refs/heads/master'
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASS }}
run: echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin

- name: push docker image
if: steps.getBranch.outputs.branch == 'master'
if: github.ref == 'refs/heads/master'
run: |
export SHORT_SHA=`git rev-parse --short=7 ${GITHUB_SHA}`
docker tag getfider/fider getfider/fider:${SHORT_SHA}
docker push getfider/fider:${SHORT_SHA}
docker tag getfider/fider getfider/fider:master
docker push getfider/fider:master
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--platform linux/386,linux/amd64,linux/arm64 \
--tag getfider/fider:${SHORT_SHA} \
--tag getfider/fider:master \
--push .
- name: cleanup
if: always() && github.ref == 'refs/heads/master'
run: |
rm -f ${HOME}/.docker/config.json
4 changes: 3 additions & 1 deletion Dockerfile
@@ -1,14 +1,16 @@
# Build Step
FROM getfider/githubci:0.0.2 AS builder

ARG TARGETPLATFORM

RUN mkdir /app
WORKDIR /app

COPY . .
RUN npm ci
RUN node -v
RUN npm -v
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 mage build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETPLATFORM##*/} mage build

# Runtime Step
FROM alpine:3.10
Expand Down

0 comments on commit efb2d82

Please sign in to comment.