Skip to content

Commit

Permalink
Merge pull request #5 from michalfita/docker
Browse files Browse the repository at this point in the history
[Fixes #2] Publish container to ghcr.io
  • Loading branch information
dbast authored Dec 26, 2023
2 parents ed4c68a + 8f531ac commit 8774bfd
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 347 deletions.
57 changes: 0 additions & 57 deletions .github/workflows/archlinuxarm-armv7-docker.yml

This file was deleted.

57 changes: 0 additions & 57 deletions .github/workflows/archlinuxarm-armv8-docker.yml

This file was deleted.

101 changes: 46 additions & 55 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ on:
push:
tags:
- 'v*'
branches: [ master ]
branches:
- master
- development
pull_request:
schedule:
# once a week
Expand All @@ -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
Expand All @@ -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 }}
23 changes: 3 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
[![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
[godoc-badge]: https://godoc.org/github.com/michalfita/packer-plugin-cross?status.svg
[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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down
76 changes: 0 additions & 76 deletions boards/armv7/archlinuxarm-docker.pkr.hcl

This file was deleted.

Loading

0 comments on commit 8774bfd

Please sign in to comment.