From 2a83cdbbb21a7b3ceb36f5fee7e5a0a03ca99bf8 Mon Sep 17 00:00:00 2001 From: Pavel Alimpiev <7024354+VaultVulp@users.noreply.github.com> Date: Sun, 30 Oct 2022 23:22:23 +0400 Subject: [PATCH 1/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d8ecfd3..2d52523 100644 --- a/README.md +++ b/README.md @@ -163,13 +163,13 @@ name: Build and publish on: push jobs: - build-with-custom-args: + build-with-multiple-tags: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build with --build-arg(s) + - name: Build with multiple tags uses: VaultVulp/gp-docker-action@1.4.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages From cd802dc8e6bffed6be8f67c40baa93b34ec47966 Mon Sep 17 00:00:00 2001 From: Pavel Alimpiev <7024354+VaultVulp@users.noreply.github.com> Date: Mon, 31 Oct 2022 01:03:15 +0400 Subject: [PATCH 2/2] Support cross-platform and multi-platform builds (#20) * Add builder instance to support cross-platform builds --- README.md | 85 +++++++++++++++++++++++++++++++++++++-------------- entrypoint.sh | 5 ++- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 2d52523..0fb1508 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ### Build and publish Docker Image with the `head` tag for the `develop` branch -#### Full workflow example: +#### Complete workflow example ```yaml name: Build and publish @@ -20,8 +20,8 @@ jobs: steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build and Publish head Docker image - uses: VaultVulp/gp-docker-action@1.4.0 + - name: Build and publish "head" Docker image + uses: VaultVulp/gp-docker-action@1.5.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages image-name: my-cool-service # Provide Docker image name @@ -30,7 +30,7 @@ jobs: ### Build and publish Docker Image with a `latest` tag for the `master` branch with different dockerfile -#### Full workflow example: +#### Complete workflow example ```yaml name: Build and publish @@ -46,8 +46,8 @@ jobs: steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build and Publish latest Docker image - uses: VaultVulp/gp-docker-action@1.4.0 + - name: Build and publish "latest" Docker image + uses: VaultVulp/gp-docker-action@1.5.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages image-name: my-cool-service # Provide only Docker image name, tag will be automatically set to latest @@ -56,7 +56,7 @@ jobs: ### Build and publish Docker Image with a tag equal to a git tag -#### Full workflow example: +#### Complete workflow example ```yaml name: Build and publish @@ -72,8 +72,8 @@ jobs: steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build and Publish Tag Docker image - uses: VaultVulp/gp-docker-action@1.4.0 + - name: Build and publish Docker image tagged according to a git-tag + uses: VaultVulp/gp-docker-action@1.5.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages image-name: my-cool-service # Provide only Docker image name @@ -82,7 +82,7 @@ jobs: ### Build and publish Docker Image with a different build context -#### Full workflow example: +#### Complete workflow example ```yaml name: Build and publish @@ -95,8 +95,8 @@ jobs: steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build and Publish Docker image from a different context - uses: VaultVulp/gp-docker-action@1.4.0 + - name: Build and publish Docker image from a different context + uses: VaultVulp/gp-docker-action@1.5.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages image-name: my-cool-service # Provide Docker image name @@ -105,7 +105,7 @@ jobs: ### Pulling an image before building it -#### Full workflow example: +#### Complete workflow example ```yaml name: Build and publish @@ -118,8 +118,8 @@ jobs: steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build and Publish head Docker image - uses: VaultVulp/gp-docker-action@1.4.0 + - name: Pull, build and publish Docker image + uses: VaultVulp/gp-docker-action@1.5.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages image-name: my-cool-service # Provide Docker image name @@ -128,9 +128,9 @@ jobs: ### Passing additional image tags -**NB**: `additional-image-tags` will **not** replace `image-tag` argument - additional tags will be appended to the list. If no `image-tag` was specified, then image will be tagged with the `latest` tag. +**NB**, `additional-image-tags` will **not** replace `image-tag` argument - additional tags will be appended to the list. If no `image-tag` was specified, then image will be tagged with the `latest` tag. -#### Examples: +#### Examples ##### `image-tag` was specified: ```yaml @@ -156,7 +156,7 @@ Action will produce one image with three tags: - `my-cool-service:second` - `my-cool-service:third` -#### Full workflow example: +#### Complete workflow example ```yaml name: Build and publish @@ -169,8 +169,8 @@ jobs: steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build with multiple tags - uses: VaultVulp/gp-docker-action@1.4.0 + - name: Build and publish Docker image with multiple tags + uses: VaultVulp/gp-docker-action@1.5.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages image-name: my-cool-service # Provide Docker image name @@ -178,6 +178,41 @@ jobs: additional-image-tags: second third # two additional tags for an image ``` +### Cross-platform builds + +It's possible to leverage `custom-args` to build images for different architectures. + +#### Examples +##### One architeture +```yaml +custom-args: --platform=linux/arm64 # target architecture +``` +##### Multiple architetures +```yaml +custom-args: --platform=linux/arm64,linux/amd64 # multiple target architectures +``` + +#### Complete workflow example +```yaml +name: Build and publish + +on: push + +jobs: + cross-platform-builds: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2.5.0 # Checking out the repo + + - name: Build and publish Docker image for ARM64 and AMD64 architectures at the same time + uses: VaultVulp/gp-docker-action@1.5.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages + image-name: my-cool-service # Provide Docker image name + custom-args: --platform=linux/arm64,linux/amd64 # specify target architectures via the `custom-args` agrument +``` + ### Passing additional arguments to the docker build command **NB**, additional arguments should be passed with the `=` sign istead of a ` `(space) between argument name and values. @@ -193,7 +228,7 @@ custom-args: --build-arg some="value" # ^ this space might break the action ``` -#### Full workflow example: +#### Complete workflow example ```yaml name: Build and publish @@ -206,14 +241,18 @@ jobs: steps: - uses: actions/checkout@v2.5.0 # Checking out the repo - - name: Build with --build-arg(s) - uses: VaultVulp/gp-docker-action@1.4.0 + - name: Build and publish Docker image with arbitrary --build-arg(s) + uses: VaultVulp/gp-docker-action@1.5.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} # Provide GITHUB_TOKEN to login into the GitHub Packages image-name: my-cool-service # Provide Docker image name custom-args: --build-arg=some="value" --build-arg=some_other="value" # Pass some additional arguments to the docker build command ``` +## My own repo with examples + +[VaultVulp/test-gp-docker-action](https://github.com/VaultVulp/test-gp-docker-action) + ## Security considerations You will encounter the following log message in your GitHub Actions Pipelines: diff --git a/entrypoint.sh b/entrypoint.sh index ea34989..510737e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -31,6 +31,5 @@ do set -- -t $DOCKER_IMAGE_NAME_WITH_TAG "$@" done -docker buildx build "$@" - -docker push --all-tags $DOCKER_IMAGE_NAME +docker buildx create --use # Creating builder instance to support cross-platform builds +docker buildx build --push "$@"