Section 3 - The build and push reusable workflow
Last updated
Last updated
Similarly to the reusable test workflow, the build and push workflow will closely resemble the one we created in Chapter 2, Section 4. The main difference is that this new workflow job will be reusable, allowing it to be called from other repositories.
We’ll start by referencing the logic used in Chapter 2, Section 4 (The build and test job) and refactor it to part of a reusable workflow.
First, we will rename the reusable-test.yaml
file located in the .github/workflows/
directory of the repository to reusable-test-build.yaml
.
Next, we’ll refactor the build and push workflow by copying it from one of our service repositories and placing it below the test
job in our newly renamed reusable workflow file. For this example, we'll use the from the test-build-and-deploy
workflow in the user-management-service
repository and modify it to be reusable.
To make the build
and push
job reusable, we’ll follow a similar process as with the test
job. Since it’s now part of a reusable workflow file, we only need to introduce the necessary inputs and utilize them within the job.
We’ll add the following inputs, providing default values for each:
image-owner: the repository owner (the ORG or username)
defaults to: ${{ github.event.repository.owner.login }}
image-name: the image name
defaults to: ${{ github.event.repository.name }}
build-tags: the build tags
defaults to:
build-push: whether to push the image after the build
defaults to:
We’ll now place the build
and push
job into the reusable workflow, integrating the inputs we just defined: