mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-11 17:50:58 +00:00
feat: add an LXC based example of docker/build-push-action usage (#781)
The motivations for this additional example are: - Using https://github.com/docker/build-push-action/ with the Forgejo runner is a recurring question and there is no example of how to do that - Reproducing https://code.forgejo.org/forgejo/runner/issues/208 will benefit from this example --- <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/781): <!--number 781 --><!--line 0 --><!--description ZmVhdDogYWRkIGFuIExYQyBiYXNlZCBleGFtcGxlIG9mIGRvY2tlci9idWlsZC1wdXNoLWFjdGlvbiB1c2FnZSBbc2tpcCBjYXNjYWRlXQ==-->feat: add an LXC based example of docker/build-push-action usage [skip cascade]<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/781 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
194c416f29
commit
51fb504a2e
4 changed files with 85 additions and 2 deletions
78
.forgejo/workflows/docker-build-push-action-in-lxc.yml
Normal file
78
.forgejo/workflows/docker-build-push-action-in-lxc.yml
Normal file
|
@ -0,0 +1,78 @@
|
|||
#
|
||||
# Example that requires a Forgejo runner with an [LXC backend](https://forgejo.org/docs/latest/admin/actions/runner-installation/#setting-up-the-container-environment).
|
||||
#
|
||||
# - Start a Forgejo instance to be used as a container registry
|
||||
# - Build a container image using the [docker/build-push-action](https://code.forgejo.org/docker/build-push-action) action
|
||||
# - Push the image to the Forgejo instance
|
||||
# - Retrieve the image
|
||||
#
|
||||
# Runs of this workflow can be seen in [the Forgejo runner](https://code.forgejo.org/forgejo/runner/actions?workflow=docker-build-push-action-in-lxc.yml) logs.
|
||||
#
|
||||
name: example
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
FORGEJO_VERSION: 11.0.3 # renovate: datasource=docker depName=code.forgejo.org/forgejo/forgejo
|
||||
FORGEJO_USER: root
|
||||
FORGEJO_PASSWORD: admin1234
|
||||
|
||||
jobs:
|
||||
docker-build-push-action-in-lxc:
|
||||
if: forge.repository_owner != 'forgejo-integration' && forge.repository_owner != 'forgejo-experimental' && forge.repository_owner != 'forgejo-release'
|
||||
runs-on: lxc-bookworm
|
||||
|
||||
steps:
|
||||
|
||||
- name: install Forgejo so it can be used as a container registry
|
||||
id: registry
|
||||
uses: https://data.forgejo.org/actions/setup-forgejo@v3.0.1
|
||||
with:
|
||||
user: ${{ env.FORGEJO_USER }}
|
||||
password: ${{ env.FORGEJO_PASSWORD }}
|
||||
binary: https://code.forgejo.org/forgejo/forgejo/releases/download/v${{ env.FORGEJO_VERSION }}/forgejo-${{ env.FORGEJO_VERSION }}-linux-amd64
|
||||
lxc-ip-prefix: 10.0.9
|
||||
|
||||
- name: enable insecure / http uploads to the Forgejo registry
|
||||
run: |-
|
||||
set -x
|
||||
# the docker daemon was implicitly installed when Forgejo was
|
||||
# installed in the previous step. But it will refuse to connect
|
||||
# to an insecure / http registry by default and must be told
|
||||
# otherwise
|
||||
cat > /etc/docker/daemon.json <<EOF
|
||||
{
|
||||
"insecure-registries" : ["${{ steps.registry.outputs.host-port }}"]
|
||||
}
|
||||
EOF
|
||||
systemctl restart docker
|
||||
|
||||
- uses: https://data.forgejo.org/docker/setup-qemu-action@v3
|
||||
- uses: https://data.forgejo.org/docker/setup-buildx-action@v2
|
||||
with:
|
||||
# insecure / http connections to the registry are allowed
|
||||
config-inline: |
|
||||
[registry."${{ steps.registry.outputs.host-port }}"]
|
||||
http = true
|
||||
|
||||
- name: login to the Forgejo registry
|
||||
uses: https://data.forgejo.org/docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ steps.registry.outputs.host-port }}
|
||||
username: ${{ env.FORGEJO_USER }}
|
||||
password: ${{ env.FORGEJO_PASSWORD }}
|
||||
|
||||
- name: build and push to the Forgejo registry
|
||||
uses: https://data.forgejo.org/docker/build-push-action@v5
|
||||
with:
|
||||
context: examples/docker-build-push-action
|
||||
push: true
|
||||
tags: ${{ steps.registry.outputs.host-port }}/root/testimage:latest
|
||||
|
||||
- name: verify the image can be read from the Forgejo registry
|
||||
run: |
|
||||
set -x
|
||||
docker pull ${{ steps.registry.outputs.host-port }}/root/testimage:latest
|
|
@ -1,9 +1,10 @@
|
|||
This directory contains a collection of usage and deployment examples.
|
||||
A collection of Forgejo actions examples.
|
||||
|
||||
Workflow examples can be found [in the documentation](https://forgejo.org/docs/next/user/actions/).
|
||||
Other examples can be found [in the documentation](https://forgejo.org/docs/next/user/actions/).
|
||||
|
||||
| Section | Description |
|
||||
|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| [`docker-build-push-action-in-lxc`](../.forgejo/workflows/docker-build-push-action-in-lxc.yml) | using the LXC runner backend to build and push a container image using the [docker/build-push-action](https://code.forgejo.org/docker/build-push-action) action |
|
||||
| [`docker`](docker) | using the host docker server by mounting the socket |
|
||||
| [`LXC systemd`](lxc-systemd) | systemd unit managing LXC containers dedicated to a single runner |
|
||||
| [`docker-compose`](docker-compose) | all in one docker-compose with the Forgejo server, the runner and docker in docker |
|
||||
|
|
1
examples/docker-build-push-action/Dockerfile
Normal file
1
examples/docker-build-push-action/Dockerfile
Normal file
|
@ -0,0 +1 @@
|
|||
FROM code.forgejo.org/oci/alpine:latest
|
3
examples/docker-build-push-action/README.md
Normal file
3
examples/docker-build-push-action/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
Used by:
|
||||
|
||||
- .forgejo/workflows/docker-build-push-action-in-lxc.yml
|
Loading…
Add table
Add a link
Reference in a new issue