There are several ways to automatically build container/docker images.
Here are a few examples:
Note: GitHub Actions can also be used with Gitea and Forgejo. ;-)
Docs:
- https://github.com/features/actions
- https://docs.github.com/en/actions
- create repository variables and secrets:
- set Workflow Permission: Settings -> Action -> General and then under Workflow permissions: Read and write permissions
- https://docs.github.com/en/actions/tutorials/create-actions/create-a-composite-action
Actions:
- checkout
- setup-qemu-action
- setup-buildx-action
- login-action
- build-push-action
- dockerhub-description or multiple-registry-description
.
├── .github
├── actions
| ├── docker-setup
| | └── action.yml
| └── ...
└── workflows
├── build_docker_images.yaml
├── build_docker_images_withMatrixAndOwnAction.yml
└── ...
├── Dockerfile(s)
└── ...
.github/workflows/build_docker_images.yamlWorkflow-File example for build Docker Images (Multiarch)- Workflow with Matrix and use own (composite) Action for building Multiarch Docker Images:
.github/actions/docker-setup/action.ymlis my docker-setup action, that can include in Workflows with(Note: You can also use the full commit SHA if you don't want to useuses: tob1as/docker-build-example/.github/actions/docker-setup@main
main.)
or when you copy the action:uses: ./.github/actions/docker-setup
.github/workflows/build_docker_images_withMatrixAndOwnAction.ymlWorkflow-File with Matrix and use own Action.- It is used in my GitHub Repository: docker-php
For GitLab use the .gitlab-ci.yml as an example.
More see in Docs.
Note: My examples are outdated, i recommend using GitHub Actions.
Docs:
Example for advanced options (hooks) and buildx for Autobuild on Docker Hub to build Multiarch Images
.
├── hooks
├── pre_build
├── build
└── push
├── Dockerfile
└── ... more Dockerfiles
.
├── alpine.Dockerfile
├── debian.Dockerfile
├── distroless.debian.Dockerfile
└── scratch.Dockerfile
This examples creates a (simple) Go application. It uses multistages and different runtime containers (with and without shell).
For more examples see in my other Repositories!
- Docker Build
- Building Multi-Architecture Docker Images With Buildx
- https://github.com/multiarch/qemu-user-static & https://github.com/tonistiigi/binfmt
More examples can be found in my repositories. Here is a selection: