Skip to content

Local registry example #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ jobs:
matrix:
buildx-version:
- latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Run local registry
run: |
docker run -d -p 5000:5000 registry:2
-
name: Checkout
uses: actions/checkout@v2.3.1
Expand All @@ -38,7 +39,6 @@ jobs:
with:
version: ${{ matrix.buildx-version }}
driver-opts: network=host
buildkitd-flags: --allow-insecure-entitlement security.insecure
-
name: Build and push
id: docker_build
Expand All @@ -47,7 +47,6 @@ jobs:
file: ./test/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
allow: network.host,security.insecure
push: true
tags: |
localhost:5000/name/app:latest
Expand All @@ -74,11 +73,12 @@ jobs:
buildx-version:
- ""
- latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Run local registry
run: |
docker run -d -p 5000:5000 registry:2
-
name: Checkout
uses: actions/checkout@v2.3.1
Expand All @@ -94,7 +94,6 @@ jobs:
with:
version: ${{ matrix.buildx-version }}
driver-opts: network=host
buildkitd-flags: --allow-insecure-entitlement security.insecure
-
name: Build and push
id: docker_build
Expand All @@ -103,7 +102,6 @@ jobs:
context: ./test
file: ./test/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
allow: network.host,security.insecure
push: true
tags: |
localhost:5000/name/app:latest
Expand Down Expand Up @@ -131,11 +129,12 @@ jobs:
dockerfile:
- multi
- multi-sudo
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Run local registry
run: |
docker run -d -p 5000:5000 registry:2
-
name: Checkout
uses: actions/checkout@v2.3.1
Expand All @@ -151,7 +150,6 @@ jobs:
with:
version: ${{ matrix.buildx-version }}
driver-opts: network=host
buildkitd-flags: --allow-insecure-entitlement security.insecure
-
name: Build and push
id: docker_build
Expand All @@ -161,7 +159,6 @@ jobs:
file: ./test/Dockerfile-${{ matrix.dockerfile }}
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
allow: network.host,security.insecure
push: true
tags: |
localhost:5000/name/app:latest
Expand All @@ -180,11 +177,12 @@ jobs:

github-cache:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Run local registry
run: |
docker run -d -p 5000:5000 registry:2
-
name: Checkout
uses: actions/checkout@v2.3.1
Expand All @@ -199,7 +197,6 @@ jobs:
uses: docker/setup-buildx-action@master
with:
driver-opts: network=host
buildkitd-flags: --allow-insecure-entitlement security.insecure
-
name: Cache Docker layers
uses: actions/cache@v2
Expand All @@ -218,7 +215,6 @@ jobs:
file: ./test/Dockerfile-multi-golang
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
allow: network.host,security.insecure
push: true
tags: |
localhost:5000/name/app:latest
Expand Down
66 changes: 43 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@master
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
-
name: Login to DockerHub
Expand All @@ -66,7 +68,6 @@ jobs:
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: user/app:latest
-
Expand All @@ -83,7 +84,6 @@ as a secret named `GIT_AUTH_TOKEN` to be able to authenticate against it with bu
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: user/app:latest
secrets: |
Expand Down Expand Up @@ -111,14 +111,9 @@ jobs:
-
name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
with:
version: latest
-
name: Login to DockerHub
uses: docker/login-action@v1
Expand All @@ -129,7 +124,6 @@ jobs:
name: Build and push
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/386
Expand Down Expand Up @@ -195,11 +189,8 @@ jobs:
-
name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
-
name: Login to DockerHub
Expand All @@ -211,7 +202,6 @@ jobs:
name: Build and push
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
Expand All @@ -221,6 +211,46 @@ jobs:
user/app:1.0.0
```

### Local registry

For testing purposes you may need to create a [local registry](https://hub.docker.com/_/registry) to push images into.

```yaml
name: ci

on:
push:
branches: master

jobs:
local-registry:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@master
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
with:
driver-opts: network=host
-
name: Build and push to local registry
uses: docker/build-push-action@v2
with:
push: true
tags: localhost:5000/name/app:latest
-
name: Inspect
run: |
docker buildx imagetools inspect localhost:5000/name/app:latest
```

### Leverage GitHub cache

You can leverage [GitHub cache](https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows)
Expand All @@ -239,7 +269,6 @@ jobs:
steps:
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
-
name: Cache Docker layers
Expand All @@ -257,17 +286,12 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: user/app:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
```

### Complete workflow
Expand Down Expand Up @@ -317,11 +341,8 @@ jobs:
-
name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
-
name: Login to DockerHub
Expand All @@ -335,7 +356,6 @@ jobs:
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/386
Expand Down