Skip to content

Commit 257c8f6

Browse files
committed
moves the krkn-hub build from push on main to tag + final image enhancement
Signed-off-by: Tullio Sebastiani <[email protected]> fixed syntax Signed-off-by: Tullio Sebastiani <[email protected]>
1 parent ce9f8aa commit 257c8f6

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

.github/workflows/docker-image.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Docker Image CI
22
on:
33
push:
4-
branches:
5-
- main
4+
tags: ['v[0-9].[0-9]+.[0-9]+']
65
pull_request:
76

87
jobs:
@@ -12,34 +11,40 @@ jobs:
1211
- name: Check out code
1312
uses: actions/checkout@v3
1413
- name: Build the Docker images
15-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
14+
if: startsWith(github.ref, 'refs/tags')
1615
run: |
17-
docker build --no-cache -t quay.io/krkn-chaos/krkn containers/
16+
docker build --no-cache -t quay.io/krkn-chaos/krkn containers/ --build-arg TAG=${GITHUB_REF#refs/tags/}
1817
docker tag quay.io/krkn-chaos/krkn quay.io/redhat-chaos/krkn
18+
docker tag quay.io/krkn-chaos/krkn quay.io/redhat-chaos/krkn:${GITHUB_REF#refs/tags/}
19+
1920
- name: Test Build the Docker images
2021
if: ${{ github.event_name == 'pull_request' }}
2122
run: |
2223
docker build --no-cache -t quay.io/krkn-chaos/krkn containers/ --build-arg PR_NUMBER=${{ github.event.pull_request.number }}
2324
- name: Login in quay
24-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
25+
if: startsWith(github.ref, 'refs/tags')
2526
run: docker login quay.io -u ${QUAY_USER} -p ${QUAY_TOKEN}
2627
env:
2728
QUAY_USER: ${{ secrets.QUAY_USERNAME }}
2829
QUAY_TOKEN: ${{ secrets.QUAY_PASSWORD }}
2930
- name: Push the KrknChaos Docker images
30-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
31-
run: docker push quay.io/krkn-chaos/krkn
31+
if: startsWith(github.ref, 'refs/tags')
32+
run: |
33+
docker push quay.io/krkn-chaos/krkn
34+
docker push quay.io/krkn-chaos/krkn:${GITHUB_REF#refs/tags/}
3235
- name: Login in to redhat-chaos quay
33-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
36+
if: startsWith(github.ref, 'refs/tags/v')
3437
run: docker login quay.io -u ${QUAY_USER} -p ${QUAY_TOKEN}
3538
env:
3639
QUAY_USER: ${{ secrets.QUAY_USER_1 }}
3740
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN_1 }}
3841
- name: Push the RedHat Chaos Docker images
39-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
40-
run: docker push quay.io/redhat-chaos/krkn
42+
if: startsWith(github.ref, 'refs/tags')
43+
run: |
44+
docker push quay.io/redhat-chaos/krkn
45+
docker push quay.io/redhat-chaos/krkn:${GITHUB_REF#refs/tags/}
4146
- name: Rebuild krkn-hub
42-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
47+
if: startsWith(github.ref, 'refs/tags')
4348
uses: redhat-chaos/actions/krkn-hub@main
4449
with:
4550
QUAY_USER: ${{ secrets.QUAY_USERNAME }}

containers/Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
FROM mcr.microsoft.com/azure-cli:latest as azure-cli
33
# oc build
44
FROM golang:1.22.4 AS oc-build
5-
RUN apt-get update && apt-get install -y libkrb5-dev
5+
RUN apt-get update && apt-get install -y --no-install-recommends libkrb5-dev
66
WORKDIR /tmp
77
RUN git clone --branch release-4.18 https://github.com/openshift/oc.git
88
WORKDIR /tmp/oc
@@ -15,6 +15,7 @@ RUN make GO_REQUIRED_MIN_VERSION:= oc
1515

1616
FROM fedora:40
1717
ARG PR_NUMBER
18+
ARG TAG
1819
RUN groupadd -g 1001 krkn && useradd -m -u 1001 -g krkn krkn
1920
RUN dnf update -y
2021

@@ -29,7 +30,9 @@ RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/s
2930
cp kubectl /usr/bin/kubectl && chmod +x /usr/bin/kubectl
3031

3132
# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
32-
RUN dnf update && dnf install -y git python39 jq yq gettext wget which
33+
RUN dnf update && dnf install -y --setopt=install_weak_deps=False \
34+
git python39 jq yq gettext wget which &&\
35+
dnf clean all
3336
# copy azure client binary from azure-cli image
3437
COPY --from=azure-cli /usr/local/bin/az /usr/bin/az
3538

@@ -41,10 +44,12 @@ RUN git clone https://github.com/krkn-chaos/krkn.git /home/krkn/kraken && \
4144
mkdir -p /home/krkn/.kube
4245

4346
WORKDIR /home/krkn/kraken
44-
# if is an event on main the variable $PR_NUMBER has no value so the latest tag is checked out else
45-
# if is a PR event the PR itself will be checked out
46-
RUN if [ -z "$PR_NUMBER" ]; then git checkout $KRKN_VERSION;\
47-
else git fetch origin pull/${PR_NUMBER}/head:pr-${PR_NUMBER} && git checkout pr-${PR_NUMBER}; fi
47+
48+
# default behaviour will be to build main
49+
# if is a PR trigger checkout the PR itself will be checked out
50+
RUN if [ -n "$PR_NUMBER" ]; then git checkout $KRKN_VERSION;fi
51+
# if is a TAG trigger checkout the tag
52+
RUN if [ -n "$TAG" ]; then git fetch origin pull/${PR_NUMBER}/head:pr-${PR_NUMBER} && git checkout pr-${PR_NUMBER};fi
4853

4954
RUN python3.9 -m ensurepip
5055
RUN pip3.9 install -r requirements.txt

0 commit comments

Comments
 (0)