ibpsa / project1-boptest

Building Optimization Performance Tests
Other
105 stars 69 forks source link

Add a GitHub Action to build, test and publish boptest containers #481

Closed tijcolem closed 1 year ago

tijcolem commented 2 years ago

This PR adds a GitHub Action to build, test and publish the boptest containers to Github packages container registry.

I tested this on my fork and the pushes to GitHub packages work well. I also included functionality (currently commented out) that can push to Docker Hub if desired. In order to push to Github packages you will need to create a new token that has write privileges to packages and create a secret in the repo called GH_REGISTRY and assign the value of the token to this. I put some more details for each step below.

1 ) To create the token for GitHub Actions to publish docker containers to the package registry, an admin will need to create a token scoped to write access for packages. And admin in the repo can create this by clicking on your profile Icon -> Settings -> Developer Settings -> Personal access tokens -> Generate new token. The token requires write:packages only (see screen grab for reference). Save the token for the next step

Screen Shot 2022-08-31 at 10 45 06 AM

2 ) You will need to create a new repo secret called GH_REGISTRY with the value of the token received from the previous step. This allows GitHub actions to authenticate to push to packages. To create the repo secret go to the repo home page (e.g. https://github.com/ibpsa/project1-boptest) and click Settings -> Secrets -> Actions -> New repository secret.

Name=GH_REGISTRY Value=Token from previous step

Once 1 & 2 are done, Github can push containers to packages. The packages in Github are within the organizational level. For example, on my forked version the example boptest containers are accessible under:

https://github.com/tijcolem?tab=packages

You can control the visibility (public, private) in each package name by clicking the package name -> Package settings.
On the first build it will be defaulted to private, so if you want these packages public you will need to change the visibility for each package name once.

The logic of this script to is build and test the containers when there is a Push, Tag or Pull Request to the boptest-service branch. A push to boptest-service branch will build, test and publish container images with "develop" as the tag name. A tag that is pushed containing the words "-service" will build, test and publish with docker images with the tag name. For example, a tag that is pushed called "v0.3.0-service" will build and publish containers with the following names boptest-web:v0.2.3-service and boptest-worker:v0.2.3-service. Below is a table showing the actions for each event.

CI Build Logic Branch Name Pull Request Push Tag
boptest-service build, test build, test, publish build, test, publish

Just a note that this is only for boptest-service branch. A push or PR to master branch for example, this CI Action will not run.

kbenne commented 2 years ago

We are going to move the boptest-service branch into a dedicated repository. It might make sense to hold this merge until that happens. @dhblum

dhblum commented 1 year ago

@kbenne Is this PR still relevant or can it be closed, given https://github.com/NREL/boptest-service?

dhblum commented 1 year ago

Thank you!