Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push Images to GHCR.io #1071

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 97 additions & 6 deletions .github/workflows/build-fb-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ on:
- 'v*'
paths:
- ".github/workflows/build-fb-image.yaml"
- ".github/workflows/scan-docker-image-action.yaml"
- "cmd/fluent-watcher/fluentbit/**"
- "cmd/fluent-watcher/hooks/**"
- "pkg/filenotify/**"

env:
FB_IMG: 'kubesphere/fluent-bit:v2.2.2'
FB_IMG_DEBUG: 'kubesphere/fluent-bit:v2.2.2-debug'
FB_IMG: "kubesphere/fluent-bit:${{ github.ref_name }}" # kubesphere/fluent-bit:v2.2.2
Copy link
Collaborator Author

@sarathchandra24 sarathchandra24 Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to recommend using GitHub action variables here, something like vars.FB_IMG. While testing actions on contributors side, it makes hard as they don't have permissions to push to this repo and it takes 1 or 2 commits to rollback to desired changes.

This follows to other env's as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful with ref_name though as it won't be what's expected for PRs.

None of this should be done by variables like this really, we should use the docker/metadata-action for this as it properly supports multiple tags and configuring them (e.g. for default branch, tags, etc.).

FB_IMG_DEBUG: "kubesphere/fluent-bit:${{ github.ref_name }}-debug" # kubesphere/fluent-bit:v2.2.2-debug

FB_IMG_GHCR: "${{ github.repository }}/fluent-bit:${{ github.ref_name }}" # fluent/fluent-operator/fluent-bit:v2.2.2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have fluent-bit image built by other https://github.com/fluent/fluent-bit/ to differentiate between the images built by both, I am pushing the image to current repository only.

FB_IMG_DEBUG_GHCR: "${{ github.repository }}/fluent-bit:${{ github.ref_name }}-debug" # fluent/fluent-operator/fluent-bit:v2.2.2-debug

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Build Image for Fluent Bit
outputs:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outputs should come from steps really, e.g. the metadata action would give you a way to get this. That way if we modify something (or for PRs, non-main branch, etc.) it will carry on working.

FB_IMG: ${{ env.FB_IMG }}
FB_IMG_DEBUG: ${{ env.FB_IMG_DEBUG }}
FB_IMG_GHCR: ${{env.FB_IMG_GHCR}}
FB_IMG_DEBUG_GHCR: ${{ env.FB_IMG_DEBUG_GHCR }}
steps:
- name: Install Go
uses: actions/setup-go@v4
Expand All @@ -36,18 +45,100 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we pushing to docker.io now instead? I would keep things in ghcr.io if you can particularly for PRs otherwise we have to start dealing with rate limiting.

username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

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

- name: Build and Push Image for Fluent Bit
run: |
make build-fb -e FB_IMG=${{ env.FB_IMG }}
make build-fb-debug -e FB_IMG_DEBUG=${{ env.FB_IMG_DEBUG }}
id: docker-build
uses: docker/build-push-action@v2
with:
context: .
file: ./cmd/fluent-watcher/fluentbit/Dockerfile
push: true
platforms: linux/amd64,linux/arm64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be pretty slow btw, it may not be worthwhile to do ARM builds for PRs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are currently building in our existing approach, so I have added.

https://github.com/fluent/fluent-operator/blob/master/Makefile#L99-L103

tags: ${{ env.FB_IMG}}

- name: Build and Push Debug Image for Fluent Bit
id: docker-build-debug
uses: docker/build-push-action@v2
with:
context: .
file: ./cmd/fluent-watcher/fluentbit/Dockerfile.debug
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.FB_IMG_DEBUG }}

scan-docker-image:
name: Scan Docker Image
needs:
- build
uses: ./.github/workflows/scan-docker-image-action.yaml
with:
source_image: ${{ needs.build.outputs.FB_IMG }}
source_registry: docker.io
platforms: '["linux/arm64", "linux/amd64"]'
secrets:
registry_username: ${{ secrets.REGISTRY_USER }}
registry_password: ${{ secrets.REGISTRY_PASSWORD }}

release-image-to-gchr:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the wrong way round, all images should start in ghcr.io as it'll be public and not rate limited. We then push to the others only release images (not all the PR images or whatever too).

name: Release Image to GitHub Container Registry
uses: ./.github/workflows/clone-docker-image-action.yaml
needs:
- scan-docker-image
- build
with:
source_image: ${{ needs.build.outputs.FB_IMG }}
source_registry: docker.io
target_image: ${{ needs.build.outputs.FB_IMG_GHCR }}
target_registry: ghcr.io
platforms: "['linux/arm64', 'linux/amd64']"
secrets:
source_registry_username: ${{ secrets.REGISTRY_USER }}
target_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.REGISTRY_PASSWORD }}
target_registry_token: ${{ secrets.GITHUB_TOKEN }}

scan-debug-image:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debug image should not be scanned, it should trigger notifications as it'll have a load of extra dependencies and is not intended for production. Any complaints about CVEs on debug images should be ignored.

name: Scan Debug Image
needs:
- build
uses: ./.github/workflows/scan-docker-image-action.yaml
with:
source_image: ${{ needs.build.outputs.FB_IMG_DEBUG }}
source_registry: docker.io
platforms: '["linux/arm64", "linux/amd64"]'
secrets:
registry_username: ${{ secrets.REGISTRY_USER }}
registry_password: ${{ secrets.REGISTRY_PASSWORD }}


release-debug-image-to-gchr:
name: Release Debug Image to GitHub Container Registry
uses: ./.github/workflows/clone-docker-image-action.yaml
needs:
- scan-debug-image
- build
with:
source_image: ${{ needs.build.outputs.FB_IMG_DEBUG }}
source_registry: docker.io
target_image: ${{ needs.build.outputs.FB_IMG_DEBUG_GHCR }}
target_registry: ghcr.io
platforms: "['linux/arm64', 'linux/amd64']"
secrets:
source_registry_username: ${{ secrets.REGISTRY_USER }}
target_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.REGISTRY_PASSWORD }}
target_registry_token: ${{ secrets.GITHUB_TOKEN }}
200 changes: 183 additions & 17 deletions .github/workflows/build-fd-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ on:
- 'v*'
paths:
- ".github/workflows/build-fd-image.yaml"
- ".github/workflows/scan-docker-image-action.yaml"
- "cmd/fluent-watcher/fluentd/**"
- "cmd/fluent-watcher/hooks/**"
- "pkg/filenotify/**"

env:
FD_IMG: 'kubesphere/fluentd:v1.15.3'
ARCH: '-arm64'
FD_IMG_BASE: 'kubesphere/fluentd:v1.15.3-arm64-base'

FD_IMG: "kubesphere/fluentd:${{ github.ref_name }}" # kubesphere/fluentd:v2.2.2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking branch name / git tag as the image tag as I couldn't figure out what to keep.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's switch to the metadata action for docker

FD_IMAGE_ARCH: "kubesphere/fluentd:${{ github.ref_name }}-arm64" # kubesphere/fluentd:v2.2.2-arm64
FD_IMAGE_ARCH_BASE: "kubesphere/fluentd:${{ github.ref_name }}-arm64-base" # kubesphere/fluentd:v2.2.2-arm64-base


FD_IMAGE_GHCR: "${{ github.repository }}/fluentd:${{ github.ref_name }}" # fluent/fluent-operator/fluentd:v2.2.2
FD_IMAGE_ARCH_GHCR: "${{ github.repository }}/fluentd:${{ github.ref_name }}-arm64" # fluent/fluent-operator/fluentd:v2.2.2-arm64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have ARM specific images but not AMD? Why not just the multiarch one?

FD_IMAGE_ARCH_BASE_GHCR: "${{ github.repository }}/fluentd:${{ github.ref_name }}-arm64-base" # fluent/fluent-operator/fluentd:v2.2.2-arm64-base

jobs:
build-amd64:
build-fluetd-amd64:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

runs-on: ubuntu-latest
timeout-minutes: 30
name: Build amd64 Image for Fluentd
name: Build Fluentd amd64 docker image
outputs:
FD_IMG: ${{ env.FD_IMG }}
FD_IMAGE_GHCR: ${{ env.FD_IMAGE_GHCR }}
steps:
- name: Install Go
uses: actions/setup-go@v4
Expand All @@ -32,6 +42,9 @@ jobs:
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -43,16 +56,59 @@ jobs:
with:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

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

- name: Build and Push amd64 Image for Fluentd
run: |
make build-fd-amd64 -e FD_IMG=${{ env.FD_IMG }}
docker push ${{ env.FD_IMG }}
- name: Build and Push Image for Fluentd
id: docker-build
uses: docker/build-push-action@v2
with:
context: .
file: ./cmd/fluent-watcher/fluentd/Dockerfile.amd64
push: true
platforms: 'linux/amd64'
tags: ${{ env.FD_IMG }}

scan-fluetd-amd64-image:
name: Trivy + Dockle scan Fluentd amd64 docker image
needs:
- build-fluetd-amd64
uses: ./.github/workflows/scan-docker-image-action.yaml
with:
source_image: "${{ needs.build-fluetd-amd64.outputs.FD_IMG }}"
source_registry: docker.io
platforms: '["linux/amd64"]'
secrets:
registry_username: ${{ secrets.REGISTRY_USER }}
registry_password: ${{ secrets.REGISTRY_PASSWORD }}

release-fluentd-amd64-image-to-ghcr:
name: Release Fluentd amd64 docker image to GitHub Container Registry
uses: ./.github/workflows/clone-docker-image-action.yaml
needs:
- build-fluetd-amd64
- scan-fluetd-amd64-image
with:
source_image: "${{ needs.build-fluetd-amd64.outputs.FD_IMG }}"
source_registry: docker.io
target_image: "${{ needs.build-fluetd-amd64.outputs.FD_IMAGE_GHCR }}"
target_registry: ghcr.io
platforms: '["linux/amd64"]'
secrets:
source_registry_username: ${{ secrets.REGISTRY_USER }}
target_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.REGISTRY_PASSWORD }}
target_registry_token: ${{ secrets.GITHUB_TOKEN }}

build-arm64:
build-fluentd-arm64-base:
runs-on: ubuntu-latest
timeout-minutes: 90
name: Build arm64 Image for Fluentd
name: Build Fluentd arm64 base image
outputs:
FD_IMAGE_ARCH_BASE: ${{ env.FD_IMAGE_ARCH_BASE }}
FD_IMAGE_ARCH_BASE_GHCR: ${{ env.FD_IMAGE_ARCH_BASE_GHCR }}
steps:
- name: Install Go
uses: actions/setup-go@v4
Expand All @@ -78,11 +134,121 @@ jobs:
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Build and Push Image for Fluentd
id: docker-build
uses: docker/build-push-action@v2
with:
context: .
file: ./cmd/fluent-watcher/fluentd/Dockerfile.arm64.base
push: true
platforms: linux/arm64
tags: ${{ env.FD_IMAGE_ARCH_BASE }}

scan-fluetd-arm64-base-image:
name: Trivy + Dockle scan Fluentd arm64 base docker image
needs:
- build-fluentd-arm64-base
uses: ./.github/workflows/scan-docker-image-action.yaml
with:
source_image: "${{ needs.build-fluentd-arm64-base.outputs.FD_IMAGE_ARCH_BASE }}"
source_registry: docker.io
platforms: '["linux/arm64"]'
secrets:
registry_username: ${{ secrets.REGISTRY_USER }}
registry_password: ${{ secrets.REGISTRY_PASSWORD }}

release-fluentd-arm64-base-image-to-ghcr:
name: Release Fluentd arm64 base docker image to GitHub Container Registry
uses: ./.github/workflows/clone-docker-image-action.yaml
needs:
- build-fluentd-arm64-base
- scan-fluetd-arm64-base-image
with:
source_image: "${{ needs.build-fluentd-arm64-base.outputs.FD_IMAGE_ARCH_BASE }}"
source_registry: docker.io
target_image: "${{ needs.build-fluentd-arm64-base.outputs.FD_IMAGE_ARCH_BASE_GHCR }}"
target_registry: ghcr.io
platforms: '["linux/arm64"]'
secrets:
source_registry_username: ${{ secrets.REGISTRY_USER }}
target_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.REGISTRY_PASSWORD }}
target_registry_token: ${{ secrets.GITHUB_TOKEN }}

build-fluentd-arm64:
runs-on: ubuntu-latest
timeout-minutes: 90
name: Build Fluentd arm64 image
outputs:
FD_IMAGE_ARCH: ${{ env.FD_IMAGE_ARCH }}
FD_IMAGE_ARCH_GHCR: ${{ env.FD_IMAGE_ARCH_GHCR }}
needs:
- build-fluentd-arm64-base
- scan-fluetd-arm64-base-image
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: Build and Push arm64 base Image for Fluentd
run: |
make build-fd-arm64-base -e FD_IMG_BASE=${{ env.FD_IMG_BASE }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Build and Push Image for Fluentd
id: docker-build
uses: docker/build-push-action@v2
with:
context: .
file: ./cmd/fluent-watcher/fluentd/Dockerfile.arm64.base
push: true
platforms: linux/arm64
tags: ${{ needs.build-fluentd-arm64-base.outputs.FD_IMAGE_ARCH_BASE }}

- name: Build and Push arm64 Image for Fluentd
run: |
make build-fd-arm64 -e FD_IMG=${{ env.FD_IMG }} -e ARCH=${{ env.ARCH }}
scan-fluetd-arm64-image:
name: Scan Fluentd arm64 docker image
needs:
- build-fluentd-arm64
uses: ./.github/workflows/scan-docker-image-action.yaml
with:
source_image: "${{ needs.build-fluentd-arm64.outputs.FD_IMAGE_ARCH }}"
source_registry: docker.io
platforms: '["linux/arm64"]'
secrets:
registry_username: ${{ secrets.REGISTRY_USER }}
registry_password: ${{ secrets.REGISTRY_PASSWORD }}

release-fluentd-arm64-image-to-ghcr:
name: Release Fluentd arm64 docker image to GitHub Container Registry
uses: ./.github/workflows/clone-docker-image-action.yaml
needs:
- build-fluentd-arm64
- scan-fluetd-arm64-image
with:
source_image: "${{ needs.build-fluentd-arm64.outputs.FD_IMAGE_ARCH }}"
source_registry: docker.io
target_image: "${{ needs.build-fluentd-arm64.outputs.FD_IMAGE_ARCH_GHCR }}"
target_registry: ghcr.io
platforms: '["linux/arm64"]'
secrets:
source_registry_username: ${{ secrets.REGISTRY_USER }}
target_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.REGISTRY_PASSWORD }}
target_registry_token: ${{ secrets.GITHUB_TOKEN }}
Loading