Skip to content

Create a GitHub action for Build Image and push against main branch #563

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

Merged
Merged
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
53 changes: 53 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build and Push dev MCAD image into Quay

on:
push:
branches:
- '*'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- '*'
- 'main'

To make sure that only push to main branch produce new image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used * because of from travis CI builds noted that we are running all the branches in upstream to build and push images to the respective branch-tag https://quay.io/repository/project-codeflare/mcad-controller?tab=tags .. If its not required we can keep this to only main

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to accommodate "patch" a release branch use case, @Srihari1192 will your code handle that use cases? (it seems that it would).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking what cases should we cover here:
New commit on main branch - new dev image published
New commit on release-<version> branch - new dev-release-<version> image published?
Any other case for producing non release image?

Those ^ are just my ideas, feel free to share your ideas.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sutaakar I think you have covered those. Is there any documentation how to "patch" a release? if we do that is great, if not we should create a separate issue / pr to create it.

I am Ok with restricting the branches to only the patterns you have outlined.

Copy link
Contributor

@sutaakar sutaakar Aug 11, 2023

Choose a reason for hiding this comment

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

I don't see any specific mention about patch release in readme. I would say it follows the similar flow as a normal release:

  • Create a release-<version> branch if not exists
  • Merge code changes until ready for patch release
  • Trigger a release workflow, specify release-<version> branch as a workflow source

Ideally this should build proper image and publish correct image tag, though I haven't tried it by myself.

Copy link
Contributor Author

@Srihari1192 Srihari1192 Aug 11, 2023

Choose a reason for hiding this comment

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

@sutaakar @z103cb I think we can put condition for assigning tag value like this. so that in case of main branch and release branch image will be pushed to the respective tag .. wdyt?


` if [[ "$GIT_BRANCH"="main" ]]; then
             echo "TAG=dev" >> $GITHUB_ENV
          else [[ "$GIT_BRANCH" == release-* ]]; then
            echo "TAG=$GIT_BRANCH" >> $GITHUB_ENV
     fi

Copy link
Contributor

Choose a reason for hiding this comment

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

in principle fine for me
just be careful on content of GIT_BRANCH, AFAIK for branch it is like refs/heads/<branch name>, see https://github.com/project-codeflare/codeflare-operator/blob/2a4731a237cf1996e6370def8c3dc7842fc2db52/.github/workflows/tag-and-build.yml#L150
Also I think that release-<branch name> format is used for released images, so you need some other name to distinguish it (i.e. like dev-release-<branch name>)

Copy link
Contributor Author

@Srihari1192 Srihari1192 Aug 11, 2023

Choose a reason for hiding this comment

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

Okay for release branch will update tag as dev-< release-branch>


jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set latest tag and Branch name
run: |
BRANCH=$(echo ${GITHUB_REF#refs/heads/})
echo "GIT_BRANCH=$(echo "$BRANCH" | sed 's/[^A-Za-z0-9._-]/-/g' )" >> $GITHUB_ENV
if [[ "$BRANCH" == "main" ]]; then
echo "TAG=dev" >> $GITHUB_ENV
elif [[ "$BRANCH" == release-* ]]; then
echo "TAG=dev-$BRANCH" >> $GITHUB_ENV
else
LATEST_TAG=$(git describe --abbrev=0 --tags)
echo "TAG=$BRANCH-$LATEST_TAG" >> $GITHUB_ENV
fi

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.10

- name: Build
run:
make mcad-controller

- name: Run Unit tests
run: make run-test

- name: Build Image
run: |
make images -e GIT_BRANCH=${{ env.GIT_BRANCH }} TAG=${{ env.TAG }}

- name: Push Image
run: |
make push-images -e GIT_BRANCH=${{ env.GIT_BRANCH }} TAG=${{ env.TAG }} quay_repository=quay.io/project-codeflare quay_id=${{ secrets.QUAY_ID }} quay_token=${{ secrets.QUAY_TOKEN }}

- name: Run E2E tests
run: |
make run-e2e -e GIT_BRANCH=${{ env.GIT_BRANCH }} TAG=${{ env.TAG }}
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CAT_CMD=$(if $(filter $(OS),Windows_NT),type,cat)
RELEASE_VER:=
CURRENT_DIR=$(shell pwd)
GIT_BRANCH:=$(shell git symbolic-ref --short HEAD 2>&1 | grep -v fatal)

#define the GO_BUILD_ARGS if you need to pass additional arguments to the go build
GO_BUILD_ARGS?=

Expand All @@ -22,16 +23,7 @@ CLIENT_GEN ?= $(LOCALBIN)/client-gen
LISTER_GEN ?= $(LOCALBIN)/lister-gen
INFORMER_GEN ?= $(LOCALBIN)/informer-gen

# Reset branch name if this a Travis CI environment
ifneq ($(strip $(TRAVIS_BRANCH)),)
GIT_BRANCH:=${TRAVIS_BRANCH}
endif

TAG:=$(shell echo "")
# Check for git repository id sent by Travis-CI
ifneq ($(strip $(git_repository_id)),)
TAG:=${TAG}${git_repository_id}-
endif

# Check for current branch name and update 'RELEASE_VER' and 'TAG'
ifneq ($(strip $(GIT_BRANCH)),)
Expand Down Expand Up @@ -184,7 +176,6 @@ push-images: verify-tag-name
ifeq ($(strip $(quay_repository)),)
$(info No registry information provided. To push images to a docker registry please set)
$(info environment variables: quay_repository, quay_token, and quay_id. Environment)
$(info variables do not need to be set for github Travis CICD.)
else
$(info Log into quay)
docker login quay.io -u ${quay_id} --password ${quay_token}
Expand All @@ -193,7 +184,7 @@ else
$(info Push the docker image to registry)
docker push ${quay_repository}/mcad-controller:${TAG}
ifeq ($(strip $(git_repository_id)),main)
$(info Update the `latest` tag when built from `main`)
$(info Update the `dev` tag when built from `main`)
docker tag mcad-controller:${TAG} ${quay_repository}/mcad-controller:latest
docker push ${quay_repository}/mcad-controller:latest
endif
Expand Down
13 changes: 6 additions & 7 deletions hack/run-e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ function update_test_host {
fi
echo "CPU architecture for downloads is: ${arch}"

#Only run this function if we are running on the travis build machinbe,
if [ "$(lsb_release -c -s 2>&1 | grep xenial)" == "xenial" ]; then
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
which curl >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "curl not installed, exiting."
exit 1
fi

which kubectl >/dev/null 2>&1
if [ $? -ne 0 ]
then
Expand Down