Skip to content

Commit

Permalink
feat: add multiple docker images (backport #2440) (#2442)
Browse files Browse the repository at this point in the history
* feat: add multiple docker images (#2440)

* Change default image && copy all go deps in 1 layer

* Extend workflow to push multiple docker images

(cherry picked from commit 4b5eccf)

# Conflicts:
#	Dockerfile

* Fix conflicts

Co-authored-by: Niccolo Raspa <[email protected]>
Co-authored-by: Niccolo Raspa <[email protected]>
  • Loading branch information
3 people authored Aug 19, 2022
1 parent ebba798 commit a76095d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 13 deletions.
111 changes: 101 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
name: docker
# This workflow pushes new osmosis docker images on every new tag.
#
# On every new `vX.Y.Z` tag the following images are pushed:
#
# osmolabs/osmosis:X.Y.Z # is pushed
# osmolabs/osmosis:X.Y # is updated to X.Y.Z
# osmolabs/osmosis:X # is updated to X.Y.Z
# osmolabs/osmosis:latest # is updated to X.Y.Z
#
# The same osmosisd binary is copied in different base runner images:
#
# - `osmolabs/osmosis:X.Y.Z` uses `gcr.io/distroless/static`
# - `osmolabs/osmosis:X.Y.Z-distroless` uses `gcr.io/distroless/static`
# - `osmolabs/osmosis:X.Y.Z-nonroot` uses `gcr.io/distroless/static:nonroot`
# - `osmolabs/osmosis:X.Y.Z-alpine` uses `alpine:3.16`
#
# All the images above have support for linux/amd64 and linux/arm64.
#
# Due to QEMU virtualization used to build multi-platform docker images
# this workflow might take a while to complete.

name: Push Docker Images

on:
push:
Expand All @@ -7,6 +28,9 @@ on:

env:
DOCKER_REPOSITORY: osmolabs/osmosis
RUNNER_BASE_IMAGE_DISTROLESS: gcr.io/distroless/static
RUNNER_BASE_IMAGE_NONROOT: gcr.io/distroless/static:nonroot
RUNNER_BASE_IMAGE_ALPINE: alpine:3.16

jobs:
docker:
Expand All @@ -17,36 +41,103 @@ jobs:
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Docker meta
id: meta
name: Find go version
id: find_go_version
run: |
GO_VERSION=$(cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
echo "::set-output name=go_version::$(echo ${GO_VERSION})"
# Distroless Docker image (default)
-
name: Docker meta (distroless)
id: meta_distroless
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_REPOSITORY }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=semver,pattern={{version}}-distroless
type=semver,pattern={{major}}.{{minor}}-distroless
type=semver,pattern={{major}}-distroless
-
name: Build and push
name: Build and push (distroless)
id: build_push_distroless
uses: docker/build-push-action@v2
with:
file: Dockerfile
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
build-args: |
GO_VERSION=${{ steps.find_go_version.outputs.go_version }}
RUNNER_IMAGE=${{ env.RUNNER_BASE_IMAGE_DISTROLESS }}
tags: ${{ steps.meta_distroless.outputs.tags }}

# Distroless nonroot Docker image
-
name: Docker meta (nonroot)
id: meta_nonroot
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_REPOSITORY }}
flavor: |
latest=false
suffix=-nonroot
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
-
name: Build and push (nonroot)
id: build_push_nonroot
uses: docker/build-push-action@v2
with:
file: Dockerfile
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
GO_VERSION=${{ steps.find_go_version.outputs.go_version }}
RUNNER_IMAGE=${{ env.RUNNER_BASE_IMAGE_NONROOT }}
tags: ${{ steps.meta_nonroot.outputs.tags }}

# Alpine Docker image
-
name: Docker meta (alpine)
id: meta_alpine
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_REPOSITORY }}
flavor: |
latest=false
suffix=-alpine
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
name: Build and push (alpine)
id: build_push_alpine
uses: docker/build-push-action@v2
with:
file: Dockerfile
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
GO_VERSION=${{ steps.find_go_version.outputs.go_version }}
RUNNER_IMAGE=${{ env.RUNNER_BASE_IMAGE_ALPINE }}
tags: ${{ steps.meta_alpine.outputs.tags }}
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.18"
ARG RUNNER_IMAGE="gcr.io/distroless/static:nonroot"
ARG RUNNER_IMAGE="gcr.io/distroless/static"

# --------------------------------------------------------
# Builder
Expand All @@ -13,8 +13,7 @@ RUN set -eux; apk add --no-cache ca-certificates build-base; apk add git linux-h

# Download go dependencies
WORKDIR /osmosis
COPY go.mod go.mod
COPY go.sum go.sum
COPY go.* .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download
Expand Down

0 comments on commit a76095d

Please sign in to comment.