diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3f58135..b25e7f8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,11 +25,6 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v3 - - - name: Build images - working-directory: ./images - run: | - make build-all - name: Login to Github Packages if: ${{ github.event_name == 'push' }} @@ -39,8 +34,15 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Push images - if: ${{ github.event_name == 'push' }} + - name: Sets PUSH env var for main push + if: ${{ github.event_name == 'push' }} + run: | + echo "PUSH=true" >> $GITHUB_ENV + + - name: Build images working-directory: ./images run: | - make docker-push + make build-all + + + diff --git a/images/Makefile b/images/Makefile index 8ed226a..3c2359c 100644 --- a/images/Makefile +++ b/images/Makefile @@ -1,4 +1,5 @@ DRY_RUN := false +PUSH := false REPOSITORY := ghcr.io/falcosecurity/kernel-testing ARCH ?= $(shell uname -m) YAML_FILE := images.yaml @@ -39,6 +40,11 @@ build-rootfs: else \ echo "Building rootfs image: $$image"; \ docker build -t $$image $$rootfs_dir; \ + if [ "$(PUSH)" = "true" ]; then \ + echo "Pushing image: $$image"; \ + docker push $$image; \ + fi \ + docker image prune -a -f; \ fi; \ done @@ -52,16 +58,11 @@ build-kernel: initrd-builder else \ echo "Building kernel image: $$image"; \ docker build -t $$image -f $$kernel_dir/Dockerfile.kernel $$kernel_dir; \ - fi; \ - done - -docker-push: - @for image in $$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "$(REPOSITORY)" | grep "$(ARCH)"); do \ - if [ "$(DRY_RUN)" = "true" ]; then \ - echo "Dry run: Pushing image: docker push $$image"; \ - else \ - echo "Pushing image: $$image"; \ - docker push $$image; \ + if [ "$(PUSH)" = "true" ]; then \ + echo "Pushing image: $$image"; \ + docker push $$image; \ + fi \ + docker image prune -a -f; \ fi; \ done diff --git a/images/README.md b/images/README.md index 28cbbbb..71fa1ac 100644 --- a/images/README.md +++ b/images/README.md @@ -2,11 +2,10 @@ Makefile present in this directory is specifically designed to generate the static Docker images required by Ignite to run tests on different Linux distributions. The workflow provided by this Makefile is designed to be straightforward, consisting of three main commands: -1. `build-all`: This target builds all the necessary Docker images for the different versions and distributions required for testing with Firecracker. +1. `build-all`: This target builds all the necessary Docker images for the different versions and distributions required for testing with Firecracker. +Optionally, you can set `PUSH=true` env variable to push the resulting Docker images to a Docker Hub registry for easier distribution and access. -2. `docker-push`: Optionally, you can use this target to push the resulting Docker images to a Docker Hub registry for easier distribution and access. - -3. `generate-yaml`: This target allows you to generate a YAML file (`images.yaml`) containing the matrix of new image information. The generated YAML file can be conveniently copied to the variables file of Ansible to keep the test environment up to date. +2. `generate-yaml`: This target allows you to generate a YAML file (`images.yaml`) containing the matrix of new image information. The generated YAML file can be conveniently copied to the variables file of Ansible to keep the test environment up to date. ## Prerequisites @@ -73,6 +72,8 @@ You can customize the Makefile to suit your specific requirements. The variables - `DRY_RUN`: Set this variable to `true` for a dry run, where the build commands will be printed but not executed. +- `PUSH`: Set this variable to `true` when executing build to also push built image to remote registry. + - `REPOSITORY`: The Docker repository where the built images will be tagged and pushed. - `ARCH`: The architecture for which the images will be built. By default, it will use the output of `uname -p`.