This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce docker container production (#660)
Introduces the production of docker containers as a CI step. Currently only provides a rolling-release version that builds on every push to main. Images are deployed to ghcr.io. The PR includes two variations on building the images. We'll likely only want to stick with one or the other.
- Loading branch information
1 parent
7d5e729
commit 127b6d0
Showing
8 changed files
with
245 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.git | ||
.gitignore | ||
.dockerignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: Publish Docker Container Images | ||
on: | ||
push: | ||
branches: [main] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
REPO_NAME: ${{ github.repository }} | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
|
||
# ------------------------------------------------------------------------------------------ | ||
# To be decided: Script-Deploy or Dockerfile-Deploy: | ||
# Script: | ||
# + Separates the golang build from the corso build. | ||
# - Haven't figured out multiplatform builds yet. | ||
# - Doesn't cache, always takes 10-15 minutes per build in the matrix. | ||
# Dockerfile: | ||
# + Once cached, takes <1m to deploy. | ||
# + Multiplatform. | ||
# + Extended features (such as tagging) can be handled by more github actions. | ||
# - When not cached, can take >2 hours to build (at least initially). | ||
# - Currently includes the complete golang:1.18 image. | ||
# ------------------------------------------------------------------------------------------ | ||
|
||
Script-Deploy: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: build | ||
strategy: | ||
matrix: | ||
BUILD_ARCH: [amd64, arm64] | ||
BUILD_OS: [linux] | ||
env: | ||
IMAGE_PREFIX: ghcr.io | ||
VERSION_SUFFIX: rolling | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run build script | ||
run: > | ||
./build-container.sh | ||
--arch ${{ matrix.BUILD_ARCH }} | ||
--prefix ${{ env.IMAGE_PREFIX }} | ||
--suffix ${{ env.VERSION_SUFFIX }} | ||
# login step boilerplate from: | ||
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio | ||
- name: Log in to registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | ||
|
||
- name: Push image | ||
env: | ||
IMAGE_ID: ${{ env.IMAGE_PREFIX }}/alcionai/corso | ||
VERSION: ${{ matrix.BUILD_OS }}-${{ matrix.BUILD_ARCH }}-${{ env.VERSION_SUFFIX }} | ||
run: | | ||
docker images -a | ||
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }} | ||
Dockerfile-Deploy: | ||
runs-on: ubuntu-latest | ||
env: | ||
TARGETOS: linux | ||
TARGETARCH: arm64 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# apparently everyone uses this step | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
# setup Docker buld action | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# In case we want to switch to dockerhub | ||
# - name: Login to DockerHub | ||
# uses: docker/login-action@v2 | ||
# with: | ||
# username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
# password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
# retrieve credentials for ghcr.io | ||
- name: Login to Github Packages | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# build the image | ||
- name: Build image and push to Docker Hub and GitHub Container Registry | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ghcr.io/alcionai/corso:rolling | ||
# use the github cache | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
# check the image digest | ||
- name: Image digest | ||
run: echo ${{ steps.docker_build.outputs.digest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# This dockerfile is configured to be run by the /corso/build/build-container.sh | ||
# script. Using docker to build this file directly will fail. | ||
|
||
FROM gcr.io/distroless/base-debian10 | ||
# FROM gcr.io/distroless/base:debug | ||
|
||
WORKDIR / | ||
|
||
COPY ./bin/corso ./ | ||
|
||
USER nonroot:nonroot | ||
|
||
ENTRYPOINT ["/corso"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# This dockerfile is able to make a quick, local image of corso. | ||
# It is not used for deployments. | ||
|
||
## Build | ||
FROM golang:1.18 AS base | ||
|
||
WORKDIR /src | ||
|
||
COPY ./src/go.mod . | ||
COPY ./src/go.sum . | ||
RUN go mod download | ||
|
||
COPY ./src . | ||
|
||
FROM base AS build | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /corso . | ||
|
||
## Deploy | ||
FROM gcr.io/distroless/base-debian10 | ||
|
||
WORKDIR / | ||
COPY --from=build /corso / | ||
|
||
COPY ./bin/corso ./ | ||
|
||
USER nonroot:nonroot | ||
|
||
ENTRYPOINT ["/corso"] | ||
ENTRYPOINT ["/corso"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// docker-bake.hcl | ||
target "docker-metadata-action" {} | ||
|
||
target "build" { | ||
inherits = ["docker-metadata-action"] | ||
context = "./" | ||
dockerfile = "Dockerfile" | ||
platforms = [ | ||
"linux/amd64", | ||
"linux/arm64", | ||
] | ||
} |