Skip to content

Commit 48fe043

Browse files
committed
chore(ci): add ci pipeline
1 parent 6c7fa07 commit 48fe043

File tree

4 files changed

+129
-11
lines changed

4 files changed

+129
-11
lines changed

.github/workflows/release.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Build/Push Images
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches: [ 'master', 'main', 'release-*' ]
11+
# Publish semver tags as releases.
12+
pull_request: {}
13+
release:
14+
types: [ 'published' ]
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY_GITHUB: ghcr.io
19+
REGISTRY_DOCKERHUB: docker.io
20+
21+
jobs:
22+
build:
23+
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
# This is used to complete the identity challenge
29+
# with sigstore/fulcio when running outside of PRs.
30+
id-token: write
31+
strategy:
32+
matrix:
33+
target: [katalyst-agent, katalyst-scheduler, katalyst-controller, katalyst-webhook, katalyst-metric]
34+
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v3
38+
39+
# Workaround: https://github.com/docker/build-push-action/issues/461
40+
- name: Setup Docker buildx
41+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
42+
43+
# Login against a Docker registry except on PR
44+
# https://github.com/docker/login-action
45+
- name: Log into registry ${{ env.REGISTRY_GITHUB }}
46+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
47+
with:
48+
registry: ${{ env.REGISTRY_GITHUB }}
49+
username: ${{ github.actor }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
- name: Log into registry ${{ env.REGISTRY_DOCKERHUB }}
52+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
53+
with:
54+
registry: ${{ env.REGISTRY_DOCKERHUB }}
55+
username: ${{ secrets.DOCKERHUB_USERNAME }}
56+
password: ${{ secrets.DOCKERHUB_TOKEN }}
57+
58+
# Extract metadata (tags, labels) for Docker
59+
# https://github.com/docker/metadata-action
60+
- name: Extract Docker metadata
61+
id: meta
62+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
63+
with:
64+
images: ${{ env.REGISTRY_GITHUB }}/${{ github.repository_owner }}/${{ matrix.target }}
65+
66+
# For pushes on main or release-* branch,
67+
# use ${repo_branch_name}-${commit_sha} as image tag
68+
- name: Set image tag for pushes
69+
id: image-tag-push
70+
if: ${{ github.event_name == 'push' }}
71+
run: echo "IMAGE_TAG=${GITHUB_REF#refs/*/}-${GITHUB_SHA}" >> $GITHUB_ENV
72+
73+
# For releases use ${repo_tag} as image tag
74+
- name: Set image tag for release
75+
id: image-tag-release
76+
if: ${{ github.event_name == 'release' }}
77+
run: echo "IMAGE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
78+
79+
# For pull requests use ${repo_sha} as image tag
80+
- name: Set image tag for pr
81+
id: image-tag-pr
82+
if: ${{ github.event_name == 'pull_request' }}
83+
run: echo "IMAGE_TAG=${GITHUB_SHA}" >> $GITHUB_ENV
84+
85+
# Build and push Docker image with Buildx (don't push on PR)
86+
# https://github.com/docker/build-push-action
87+
- name: Build and push Docker image
88+
id: build-and-push
89+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
90+
with:
91+
context: .
92+
platforms: linux/amd64,linux/arm64
93+
file: build/dockerfiles/Dockerfile
94+
push: ${{ github.event_name != 'pull_request' }}
95+
build-args: |
96+
BINARY=${{ matrix.target }}
97+
tags: |
98+
${{ env.REGISTRY_GITHUB }}/${{ github.repository_owner }}/${{ matrix.target }}:${{ env.IMAGE_TAG }}
99+
${{ env.REGISTRY_DOCKERHUB }}/${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.target }}:${{ env.IMAGE_TAG }}
100+
labels: ${{ steps.meta.outputs.labels }}
101+
cache-from: type=gha,target={{ matrix.target }}
102+
cache-to: type=gha,mode=max,target={{ matrix.target }}

build/dockerfiles/Dockerfile

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# todo
16-
# once all code is public, enable multi-stage build
17-
# FROM --platform=${BUILDPLATFORM} golang:1.18 as builder
18-
# ADD . /build
19-
# ARG TARGETOS TARGETARCH GIT_VERSION
20-
# ARG BINARY
21-
# WORKDIR /build/
22-
# RUN make build-linux TARGET=${BINARY}
15+
FROM --platform=${BUILDPLATFORM} golang:1.18 as builder
16+
ADD . /build
17+
ARG TARGETOS TARGETARCH GIT_VERSION
18+
ARG BINARY
19+
WORKDIR /build/
20+
RUN make build-binaries TARGET=${BINARY} TARGET_ARCHS=${TARGETARCH}
2321

2422
FROM --platform=${BUILDPLATFORM} kubewharf/distroless-base-debian11:latest
2523
ARG TARGETOS TARGETARCH
2624
ARG BINARY
27-
#COPY --from=builder /build/output/bin/${TARGETOS}/${TARGETARCH}/${BINARY} /usr/local/bin/${BINARY}
28-
COPY ./output/bin/${TARGETOS}/${TARGETARCH}/${BINARY} /usr/local/bin/${BINARY}
25+
COPY --from=builder /build/output/bin/${TARGETOS}/${TARGETARCH}/${BINARY} /usr/local/bin/${BINARY}

build/dockerfiles/Dockerfile.local

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2022 The Katalyst Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM kubewharf/distroless-base-debian11:latest
16+
ARG TARGETOS TARGETARCH
17+
ARG BINARY
18+
19+
COPY ./output/bin/${TARGETOS}/${TARGETARCH}/${BINARY} /usr/local/bin/${BINARY}

build/lib/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TARGET_ARCHS=${TARGET_ARCHS:-""}
1818

1919
OUTPUT_DIR=${ROOT_DIR}/output
2020
BIN_DIR=${OUTPUT_DIR}/bin
21-
DOCKERFILE=${ROOT_DIR}/build/dockerfiles/Dockerfile
21+
DOCKERFILE=${ROOT_DIR}/build/dockerfiles/Dockerfile.local
2222

2323
PROJECT_PREFIX=${PROJECT_PREFIX:-katalyst}
2424
GIT_VERSION=${GIT_VERSION:-$(git describe --abbrev=0 --tags --always)}

0 commit comments

Comments
 (0)