From 084e6c9ba4de26f61bbc31615f7ac53e3756d8fd Mon Sep 17 00:00:00 2001 From: Daniel Bast <2790401+dbast@users.noreply.github.com> Date: Tue, 26 Dec 2023 18:43:04 +0100 Subject: [PATCH 1/3] Publish container to ghcr.io Remove arch linux armv7/v8 docker containers. --- .../workflows/archlinuxarm-armv7-docker.yml | 57 ---------- .../workflows/archlinuxarm-armv8-docker.yml | 57 ---------- .github/workflows/docker.yml | 101 ++++++++---------- boards/armv7/archlinuxarm-docker.pkr.hcl | 76 ------------- boards/armv8/archlinuxarm-docker.pkr.hcl | 79 -------------- docker/Dockerfile | 2 +- 6 files changed, 47 insertions(+), 325 deletions(-) delete mode 100644 .github/workflows/archlinuxarm-armv7-docker.yml delete mode 100644 .github/workflows/archlinuxarm-armv8-docker.yml delete mode 100644 boards/armv7/archlinuxarm-docker.pkr.hcl delete mode 100644 boards/armv8/archlinuxarm-docker.pkr.hcl diff --git a/.github/workflows/archlinuxarm-armv7-docker.yml b/.github/workflows/archlinuxarm-armv7-docker.yml deleted file mode 100644 index 24c3cbc..0000000 --- a/.github/workflows/archlinuxarm-armv7-docker.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Archlinuxarm armv7 docker -on: - push: - branches: [ master ] - schedule: - # once a week - - cron: '0 0 * * 1' -jobs: - - build: - name: Push archlinuxarm-armv7 image to docker registry - runs-on: ubuntu-latest - steps: - - name: Set up Go 1.21 - uses: actions/setup-go@v5.0.0 - with: - go-version: '1.21' - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v4.1.1 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Fetch additional packages - run: | - sudo apt-get update - sudo apt-get install fdisk gdisk qemu-user-static libarchive-tools tar - - - name: Build - run: go build -v . - - - name: Install Packer - uses: hashicorp-contrib/setup-packer@v3 - with: - packer-version: 1.10.0 - - - name: Install packer plugins - run: sudo packer init boards/armv7/archlinuxarm-docker.pkr.hcl - - - name: Build image - run: | - sudo packer build \ - -var docker_user=$docker_user \ - -var docker_password=$docker_password \ - -var docker_repository=$docker_repository \ - boards/armv7/archlinuxarm-docker.pkr.hcl - env: - docker_user: ${{ secrets.docker_user }} - docker_password: ${{ secrets.docker_password }} - docker_repository: mkaczanowski/archlinuxarm diff --git a/.github/workflows/archlinuxarm-armv8-docker.yml b/.github/workflows/archlinuxarm-armv8-docker.yml deleted file mode 100644 index efacd52..0000000 --- a/.github/workflows/archlinuxarm-armv8-docker.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Archlinuxarm armv8 docker -on: - push: - branches: [ master ] - schedule: - # once a week - - cron: '0 0 * * 1' -jobs: - - build: - name: Push archlinuxarm-armv7 image to docker registry - runs-on: ubuntu-latest - steps: - - name: Set up Go 1.21 - uses: actions/setup-go@v5.0.0 - with: - go-version: '1.21' - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v4.1.1 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Fetch additional packages - run: | - sudo apt-get update - sudo apt-get install fdisk gdisk qemu-user-static libarchive-tools tar - - - name: Build - run: go build -v . - - - name: Install Packer - uses: hashicorp-contrib/setup-packer@v3 - with: - packer-version: 1.10.0 - - - name: Install packer plugins - run: sudo packer init boards/armv8/archlinuxarm-docker.pkr.hcl - - - name: Build image - run: | - sudo packer build \ - -var docker_user=$docker_user \ - -var docker_password=$docker_password \ - -var docker_repository=$docker_repository \ - boards/armv8/archlinuxarm-docker.pkr.hcl - env: - docker_user: ${{ secrets.docker_user }} - docker_password: ${{ secrets.docker_password }} - docker_repository: mkaczanowski/archlinuxarm diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b5f5db3..9da93d1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,7 +5,9 @@ on: push: tags: - 'v*' - branches: [ master ] + branches: + - master + - development pull_request: schedule: # once a week @@ -15,6 +17,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: docker: runs-on: ubuntu-latest @@ -34,71 +40,56 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - #- name: Docker meta - # id: meta - # uses: docker/metadata-action@v5 - # with: - # images: | - # mkaczanowski/packer-builder-arm - # tags: | - # type=ref,event=branch - # type=ref,event=pr - # type=match,pattern=v(.*),group=1 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=match,pattern=v(.*),group=1 - #### build+export, test only on PRs - #- name: Build and export to Docker - # if: github.event_name == 'pull_request' - # uses: docker/build-push-action@v5 - # with: - # context: . - # file: docker/Dockerfile - # load: true - # tags: packer-plugin-cross:test - # labels: ${{ steps.meta.outputs.labels }} + ### build+export, test only on PRs + - name: Build and export to Docker + if: github.event_name == 'pull_request' + uses: docker/build-push-action@v5 + with: + context: . + file: docker/Dockerfile + load: true + tags: packer-plugin-cross:test + labels: ${{ steps.meta.outputs.labels }} - name: Install packer plugins if: github.event_name == 'pull_request' run: | - docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build packer-builder-arm:test init boards/raspberry-pi-4/archlinuxarm.pkr.hcl + docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build packer-plugin-cross:test init boards/raspberry-pi-4/archlinuxarm.pkr.hcl - name: Test build board if: github.event_name == 'pull_request' run: | - docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build packer-builder-arm:test build boards/raspberry-pi-4/archlinuxarm.pkr.hcl -extra-system-packages=bmap-tools,zstd + docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build packer-plugin-cross:test build boards/raspberry-pi-4/archlinuxarm.pkr.hcl -extra-system-packages=bmap-tools,zstd du -h raspberry-pi-4.img du -h --apparent-size raspberry-pi-4.img #### - # - name: Login to DockerHub - # uses: docker/login-action@v3 - # if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags') - # with: - # username: ${{ secrets.DOCKER_USER }} - # password: ${{ secrets.DOCKER_PASSWORD }} - - # - name: Login to GitHub Container Registry - # uses: docker/login-action@v3 - # with: - # registry: ghcr.io - # username: ${{ github.repository_owner }} - # password: ${{ secrets.GHCR_IO_REGISTRY_TOKEN }} - - #- name: Build and push - # uses: docker/build-push-action@v5 - # if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags') }} - # with: - # context: . - # file: docker/Dockerfile - # platforms: linux/amd64,linux/arm64 - # push: true - # tags: ${{ steps.meta.outputs.tags }} - # labels: ${{ steps.meta.outputs.labels }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development' || startsWith(github.ref, 'refs/tags') }} + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - #- name: Update description - # uses: peter-evans/dockerhub-description@v3 - # if: github.ref == 'refs/heads/master' - # with: - # username: ${{ secrets.DOCKER_USER }} - # password: ${{ secrets.DOCKER_PASSWORD }} - # short-description: Packer plugin to build ARM images - # readme-filepath: ./README.md + - name: Build and push + uses: docker/build-push-action@v5 + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development' || startsWith(github.ref, 'refs/tags') }} + with: + context: . + file: docker/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/boards/armv7/archlinuxarm-docker.pkr.hcl b/boards/armv7/archlinuxarm-docker.pkr.hcl deleted file mode 100644 index eda5aa2..0000000 --- a/boards/armv7/archlinuxarm-docker.pkr.hcl +++ /dev/null @@ -1,76 +0,0 @@ -# See https://www.packer.io/docs/templates/hcl_templates/blocks/packer for more info -packer { - required_plugins { - docker = { - source = "github.com/hashicorp/docker" - version = "~> 1" - } - } -} - -variable "docker_password" { - type = string - default = "" -} - -variable "docker_repository" { - type = string - default = "" -} - -variable "docker_user" { - type = string - default = "" -} - -# https://www.packer.io/docs/templates/hcl_templates/blocks/source -source "cross" "autogenerated_1" { - file_checksum_type = "md5" - file_checksum_url = "http://hu.mirror.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz.md5" - file_target_extension = "tar.gz" - file_unarchive_cmd = ["bsdtar", "-xpf", "$ARCHIVE_PATH", "-C", "$MOUNTPOINT"] - file_urls = ["http://hu.mirror.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz"] - image_build_method = "new" - image_partitions { - filesystem = "ext4" - mountpoint = "/" - name = "root" - size = "0" - start_sector = "4096" - type = "83" - } - image_path = "armv7.tar.gz" - image_size = "2G" - image_type = "dos" - qemu_binary_destination_path = "/usr/bin/qemu-arm-static" - qemu_binary_source_path = "/usr/bin/qemu-arm-static" -} - -# https://www.packer.io/docs/templates/hcl_templates/blocks/build -build { - sources = ["source.cross.autogenerated_1"] - - provisioner "shell" { - inline = [ - "pacman-key --init", - "pacman-key --populate archlinuxarm", - "echo 'Server = http://nl.mirror.archlinuxarm.org/$arch/$repo' >> /etc/pacman.d/mirrorlist" - ] - } - - post-processors { - post-processor "artifice" { - files = ["armv7.tar.gz"] - } - post-processor "docker-import" { - platform = "linux/arm/v7" - repository = "${var.docker_repository}" - tag = "armv7" - } - post-processor "docker-push" { - login = true - login_password = "${var.docker_password}" - login_username = "${var.docker_user}" - } - } -} diff --git a/boards/armv8/archlinuxarm-docker.pkr.hcl b/boards/armv8/archlinuxarm-docker.pkr.hcl deleted file mode 100644 index 15c264d..0000000 --- a/boards/armv8/archlinuxarm-docker.pkr.hcl +++ /dev/null @@ -1,79 +0,0 @@ -# See https://www.packer.io/docs/templates/hcl_templates/blocks/packer for more info -packer { - required_plugins { - docker = { - source = "github.com/hashicorp/docker" - version = "~> 1" - } - } -} - -# https://www.packer.io/docs/templates/hcl_templates/variables#type-constraints for more info. -variable "docker_password" { - type = string - default = "" -} - -variable "docker_repository" { - type = string - default = "" -} - -variable "docker_user" { - type = string - default = "" -} - -# https://www.packer.io/docs/templates/hcl_templates/blocks/source -source "cross" "autogenerated_1" { - file_checksum_type = "md5" - file_checksum_url = "http://hu.mirror.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz.md5" - file_target_extension = "tar.gz" - file_unarchive_cmd = ["bsdtar", "-xpf", "$ARCHIVE_PATH", "-C", "$MOUNTPOINT"] - file_urls = ["http://hu.mirror.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz"] - image_build_method = "new" - image_partitions { - filesystem = "ext4" - mountpoint = "/" - name = "root" - size = "0" - start_sector = "4096" - type = "83" - } - image_path = "armv8.tar.gz" - image_size = "2G" - image_type = "dos" - qemu_binary_destination_path = "/usr/bin/qemu-aarch64-static" - qemu_binary_source_path = "/usr/bin/qemu-aarch64-static" -} - -# a build block invokes sources and runs provisioning steps on them. The -# documentation for build blocks can be found here: -# https://www.packer.io/docs/templates/hcl_templates/blocks/build -build { - sources = ["source.cross.autogenerated_1"] - - provisioner "shell" { - inline = [ - "pacman-key --init", - "pacman-key --populate archlinuxarm", - "echo 'Server = http://nl.mirror.archlinuxarm.org/$arch/$repo' >> /etc/pacman.d/mirrorlist" - ] - } - - post-processors { - post-processor "artifice" { - files = ["armv8.tar.gz"] - } - post-processor "docker-import" { - platform = "linux/arm64" - repository = "${var.docker_repository}" - tag = "armv8" - } - post-processor "docker-push" { - login = true - login_password = "${var.docker_password}" - login_username = "${var.docker_user}" - } - } -} diff --git a/docker/Dockerfile b/docker/Dockerfile index d31e1ee..2384ff0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -64,7 +64,7 @@ RUN apt-get update -qq \ WORKDIR /build COPY docker/entrypoint.sh /entrypoint.sh -COPY --from=builder /build/packer-builder-arm /bin/packer /bin/ +COPY --from=builder /build/packer-plugin-cross /bin/packer /bin/ COPY --from=qemu_binaries /binaries/* /usr/bin/ # Enable detailed logging From 6d20747cdc41b6738cef59ef94fac8a27aa284db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Fita?= <4925040+michalfita@users.noreply.github.com> Date: Tue, 26 Dec 2023 18:57:02 +0000 Subject: [PATCH 2/3] [Fixes #2] Scope creep: last rename fix --- builder/artifact.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/artifact.go b/builder/artifact.go index a80645f..8d3f4c6 100644 --- a/builder/artifact.go +++ b/builder/artifact.go @@ -2,14 +2,14 @@ package builder import "os" -// Artifact represents the image produced by packer-builder-arm +// Artifact represents the image produced by packer-plugin-cross type Artifact struct { image string } // BuilderId returns builder ID func (a *Artifact) BuilderId() string { //nolint:all - return "builder-arm" + return "plugin-cross" } // Files returns list of images (in that case just one) built From 8f531ac0e8516a25434611d2be53d485fa02bfe2 Mon Sep 17 00:00:00 2001 From: Daniel Bast <2790401+dbast@users.noreply.github.com> Date: Tue, 26 Dec 2023 20:06:21 +0100 Subject: [PATCH 3/3] Update README --- README.md | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e0f8d1d..1e4a883 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,6 @@ [![Build Status][github-badge]][github] [![GoDoc][godoc-badge]][godoc] [![GoReportCard][report-badge]][report] -[![Docker Pulls][docker-pulls]][docker-hub] -[![Docker Image Size][docker-size]][docker-hub] -[![Docker Image Version][docker-version]][docker-hub] [github-badge]:https://img.shields.io/github/actions/workflow/status/michalfita/packer-plugin-cross/docker.yml?branch=master [github]: https://github.com/michalfita/packer-plugin-cross/actions @@ -16,11 +13,6 @@ [godoc]: https://godoc.org/github.com/michalfita/packer-plugin-cross [report-badge]: https://goreportcard.com/badge/github.com/michalfita/packer-plugin-cross [report]: https://goreportcard.com/report/github.com/michalfita/packer-plugin-cross -[docker-hub]: https://hub.docker.com/r/michalfita/packer-plugin-cross -[docker-pulls]: https://img.shields.io/docker/pulls/michalfita/packer-plugin-cross -[docker-size]: https://img.shields.io/docker/image-size/michalfita/packer-plugin-cross -[docker-version]: https://img.shields.io/docker/v/michalfita/packer-plugin-cross?sort=semver - This plugin allows you to build or extend cross-platform system image. It operates in three modes: * new - creates empty disk image and populates the `rootfs` on it @@ -74,21 +66,18 @@ The container is a multi-arch container (linux/amd64 or linux/arm64), that can b ### Usage via container from Docker Hub: -> ![WARNING] -> Not supported at the moment, I plan to use `ghcr.io` instead. - Pull the latest version of the container to ensure the next commands are not using an old cached version of the container: ``` -docker pull michalfita/packer-plugin-cross:latest +docker pull ghcr.io/michalfita/packer-plugin-cross:latest ``` Build a board: ``` -docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build michalfita/packer-plugin-cross:latest build boards/raspberry-pi/raspbian.json +docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build ghcr.io/michalfita/packer-plugin-cross:latest build boards/raspberry-pi/raspbian.json ``` Build a board with more system packages (e.g. bmap-tools, zstd) can be added via the parameter `-extra-system-packages=...`: ``` -docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build michalfita/packer-plugin-cross:latest build boards/raspberry-pi/raspbian.json -extra-system-packages=bmap-tools,zstd +docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build ghcr.io/michalfita/packer-plugin-cross:latest build boards/raspberry-pi/raspbian.json -extra-system-packages=bmap-tools,zstd ``` > ![TIP] @@ -253,12 +242,6 @@ With `artifice` plugin you can pass rootfs archive to docker plugins ] ``` -## CI/CD -This is the live example on how to use GitHub Actions to push image to docker image registry: -``` -cat .github/workflows/archlinuxarm-armv7-docker.yml -``` - ## How is this plugin different from `solo-io/packer-plugin-cross-image` https://github.com/hashicorp/packer/pull/8462