From b0acf4a8d692fc9d0e774729a06d6dde427f5007 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 5 Sep 2020 05:18:00 +0200 Subject: [PATCH 1/4] Add example with local registry Signed-off-by: CrazyMax --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3cd049d..003e67f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 - @@ -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: | @@ -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 @@ -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 @@ -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 @@ -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 @@ -221,6 +211,54 @@ 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: Checkout + uses: actions/checkout@v2 + - + 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 + #buildkitd-flags: --allow-insecure-entitlement security.insecure # default + - + name: Build and push to local registry + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + allow: network.host,security.insecure + 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) @@ -239,7 +277,6 @@ jobs: steps: - name: Set up Docker Buildx - id: buildx uses: docker/setup-buildx-action@master - name: Cache Docker layers @@ -260,7 +297,6 @@ jobs: 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 @@ -317,8 +353,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@master - with: - platforms: all - name: Set up Docker Buildx id: buildx From 562df850e812d32fe9b412c07d18e8a04b7a953a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 5 Sep 2020 05:18:15 +0200 Subject: [PATCH 2/4] Use service container Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68de37d..793e83f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -74,11 +75,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 @@ -131,11 +133,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 @@ -180,11 +183,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 From c9c37b8060620472616417349c8082108779eb19 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 5 Sep 2020 15:34:15 +0200 Subject: [PATCH 3/4] Skip not needed Signed-off-by: CrazyMax --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 003e67f..84f5e3d 100644 --- a/README.md +++ b/README.md @@ -231,9 +231,6 @@ jobs: ports: - 5000:5000 steps: - - - name: Checkout - uses: actions/checkout@v2 - name: Set up QEMU uses: docker/setup-qemu-action@master @@ -247,9 +244,6 @@ jobs: name: Build and push to local registry uses: docker/build-push-action@v2 with: - context: . - file: ./Dockerfile - platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x allow: network.host,security.insecure push: true tags: localhost:5000/name/app:latest From b4bae2181a201bee645407be099166b9529d6dbc Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 8 Sep 2020 11:25:47 +0200 Subject: [PATCH 4/4] Simplify workflow Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 8 -------- README.md | 8 -------- 2 files changed, 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 793e83f..ff16893 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,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 @@ -48,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 @@ -96,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 @@ -105,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 @@ -154,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 @@ -164,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 @@ -203,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 @@ -222,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 diff --git a/README.md b/README.md index 84f5e3d..31360db 100644 --- a/README.md +++ b/README.md @@ -239,12 +239,10 @@ jobs: uses: docker/setup-buildx-action@master with: driver-opts: network=host - #buildkitd-flags: --allow-insecure-entitlement security.insecure # default - name: Build and push to local registry uses: docker/build-push-action@v2 with: - allow: network.host,security.insecure push: true tags: localhost:5000/name/app:latest - @@ -288,16 +286,12 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push - id: docker_build uses: docker/build-push-action@v2 with: 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 @@ -349,7 +343,6 @@ jobs: uses: docker/setup-qemu-action@master - name: Set up Docker Buildx - id: buildx uses: docker/setup-buildx-action@master - name: Login to DockerHub @@ -363,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