Docker Workflow #26847
-
Hello everyone! I am new to GitHub Actions. I am wondering if there are experienced people who can offer advice on setting up CI pipeline involving Docker container. Ideally, I would like to do the following inside the same job: (1) build the Docker image, (2) run unit tests inside the container, (3) push the built image up to Docker Hub if the tests pass. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
That’s definitely possible, I have an example of a similar setup here (pushing to GHCR instead): https://github.com/airtower-luna/hello-ghcr/blob/763f10f3fdc33e8bcef1d04508a3264cf1a06c16/.github/workflows/build.yaml I just use the regular Your tests will probably look pretty different, for the simple test container I only do |
Beta Was this translation helpful? Give feedback.
-
Thanks very much for this. I don’t know much about writing logic inside of YAML files, do you have any suggested resources? Specifically, I want to write logic where I have this step
where TAG_NAME is ‘staging’ if I push to develop branch and ‘prod’ if I push to master branch |
Beta Was this translation helpful? Give feedback.
-
lpzhang5:
There isn’t much. YAML itself is structured data. Github Actions defines some fields that can contain logic (mostly
lpzhang5:
You might have noticed this step in my example:
The Whether it makes sense to create a script file like I did or put the script directly into a step is part a matter of taste and also depends on how complex your selection is. You could just do something like this for what you described:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your help. I have adapted the logic you have written and workflow is working as intended. I have also learned quite a bit about the general process, previously I was very unfamiliar. |
Beta Was this translation helpful? Give feedback.
There isn’t much. YAML itself is structured data. Github Actions defines some fields that can contain logic (mostly
if:
on steps or jobs). Most of the logic in your workflow will have to be in the steps.You might have noticed this step in my example: