From e090350180aada8fd5fed2ab70a00fda6016d58b Mon Sep 17 00:00:00 2001
From: CrazyMax <crazy-max@users.noreply.github.com>
Date: Mon, 20 Feb 2023 22:54:11 +0100
Subject: [PATCH 1/4] ci: split validate and test workflow

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
---
 .github/workflows/ci.yml       |  5 +++--
 .github/workflows/test.yml     |  8 +------
 .github/workflows/validate.yml | 41 ++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 9 deletions(-)
 create mode 100644 .github/workflows/validate.yml

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 93409a3..59b4d4d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -11,12 +11,13 @@ on:
         description: 'BuildKit image'
         default: 'moby/buildkit:buildx-stable-1'
         required: false
+  schedule:
+    - cron: '0 10 * * *'
   push:
     branches:
       - 'master'
+      - 'releases/v*'
   pull_request:
-    branches:
-      - 'master'
 
 env:
   BUILDX_VERSION: latest
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 489557a..80a52e3 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -4,9 +4,8 @@ on:
   push:
     branches:
       - 'master'
+      - 'releases/v*'
   pull_request:
-    branches:
-      - 'master'
 
 jobs:
   test:
@@ -15,11 +14,6 @@ jobs:
       -
         name: Checkout
         uses: actions/checkout@v3
-      -
-        name: Validate
-        uses: docker/bake-action@v2
-        with:
-          targets: validate
       -
         name: Test
         uses: docker/bake-action@v2
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
new file mode 100644
index 0000000..33fc0db
--- /dev/null
+++ b/.github/workflows/validate.yml
@@ -0,0 +1,41 @@
+name: validate
+
+on:
+  push:
+    branches:
+      - 'master'
+      - 'releases/v*'
+  pull_request:
+
+jobs:
+  prepare:
+    runs-on: ubuntu-latest
+    outputs:
+      targets: ${{ steps.targets.outputs.matrix }}
+    steps:
+      -
+        name: Checkout
+        uses: actions/checkout@v3
+      -
+        name: Targets matrix
+        id: targets
+        run: |
+          echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.validate.targets')" >> $GITHUB_OUTPUT
+
+  validate:
+    runs-on: ubuntu-latest
+    needs:
+      - prepare
+    strategy:
+      fail-fast: false
+      matrix:
+        target: ${{ fromJson(needs.prepare.outputs.targets) }}
+    steps:
+      -
+        name: Checkout
+        uses: actions/checkout@v3
+      -
+        name: Validate
+        uses: docker/bake-action@v2
+        with:
+          targets: ${{ matrix.target }}

From e9c0697e5b0d897cc64da03a158de6627a45b963 Mon Sep 17 00:00:00 2001
From: CrazyMax <crazy-max@users.noreply.github.com>
Date: Mon, 20 Feb 2023 22:54:40 +0100
Subject: [PATCH 2/4] ci: virtual-env workflow moved to actions-toolkit repo

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
---
 .github/workflows/virtual-env.yml | 72 -------------------------------
 1 file changed, 72 deletions(-)
 delete mode 100644 .github/workflows/virtual-env.yml

diff --git a/.github/workflows/virtual-env.yml b/.github/workflows/virtual-env.yml
deleted file mode 100644
index 590af32..0000000
--- a/.github/workflows/virtual-env.yml
+++ /dev/null
@@ -1,72 +0,0 @@
-name: virtual-env
-
-on:
-  workflow_dispatch:
-  schedule:
-    - cron: '0 10 * * *'
-  push:
-    branches:
-      - 'master'
-    paths:
-      - '.github/workflows/virtual-env.yml'
-  pull_request:
-    branches:
-      - 'master'
-    paths:
-      - '.github/workflows/virtual-env.yml'
-
-jobs:
-  os:
-    runs-on: ${{ matrix.os }}
-    strategy:
-      fail-fast: false
-      matrix:
-        os:
-          - ubuntu-latest
-          - ubuntu-22.04
-          - ubuntu-20.04
-          - ubuntu-18.04
-    steps:
-      -
-        name: File system
-        run: df -ah
-      -
-        name: Mounts
-        run: mount
-      -
-        name: Node info
-        run: node -p process
-      -
-        name: NPM version
-        run: npm version
-      -
-        name: List install packages
-        run: apt list --installed
-      -
-        name: Docker daemon conf
-        run: |
-          cat /etc/docker/daemon.json
-      -
-        name: Docker info
-        run: docker info
-      -
-        name: Docker version
-        run: docker version
-      -
-        name: Cgroups
-        run: |
-          sudo apt-get install -y cgroup-tools
-          lscgroup
-      -
-        name: buildx version
-        run: docker buildx version
-      -
-        name: containerd version
-        run: containerd --version
-      -
-        name: Docker images
-        run: docker image ls
-      -
-        name: Dump context
-        if: always()
-        uses: crazy-max/ghaction-dump-context@v2

From 5c3465b033b316f84a1018940d1465822bc909f0 Mon Sep 17 00:00:00 2001
From: CrazyMax <crazy-max@users.noreply.github.com>
Date: Mon, 20 Feb 2023 22:59:45 +0100
Subject: [PATCH 3/4] ci: merge example workflow to ci one

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
---
 .github/workflows/ci.yml      | 63 +++++++++++++++++++++++++++++
 .github/workflows/example.yml | 74 -----------------------------------
 2 files changed, 63 insertions(+), 74 deletions(-)
 delete mode 100644 .github/workflows/example.yml

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 59b4d4d..3ac9849 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -200,6 +200,69 @@ jobs:
             exit 1
           fi
 
+  example:
+    runs-on: ubuntu-latest
+    env:
+      DOCKER_IMAGE: localhost:5000/name/app
+    services:
+      registry:
+        image: registry:2
+        ports:
+          - 5000:5000
+    steps:
+      -
+        name: Checkout
+        uses: actions/checkout@v3
+      -
+        name: Docker meta
+        id: meta
+        uses: docker/metadata-action@v4
+        with:
+          images: ${{ env.DOCKER_IMAGE }}
+          tags: |
+            type=schedule
+            type=ref,event=branch
+            type=ref,event=pr
+            type=semver,pattern={{version}}
+            type=semver,pattern={{major}}.{{minor}}
+            type=semver,pattern={{major}}
+            type=sha
+      -
+        name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v2
+        with:
+          version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
+          driver-opts: |
+            network=host
+            image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
+      -
+        name: Build and export to Docker client
+        uses: ./
+        with:
+          context: ./test
+          file: ./test/Dockerfile
+          load: true
+          tags: ${{ steps.meta.outputs.tags }}
+          labels: ${{ steps.meta.outputs.labels }}
+      -
+        name: Build and push to local registry
+        uses: ./
+        with:
+          context: ./test
+          file: ./test/Dockerfile
+          push: ${{ github.event_name != 'pull_request' }}
+          tags: ${{ steps.meta.outputs.tags }}
+          labels: ${{ steps.meta.outputs.labels }}
+      -
+        name: Inspect image
+        run: |
+          docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }}
+      -
+        name: Check manifest
+        if: github.event_name != 'pull_request'
+        run: |
+          docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }} --format '{{json .}}'
+
   error:
     runs-on: ubuntu-latest
     steps:
diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml
deleted file mode 100644
index 74f1109..0000000
--- a/.github/workflows/example.yml
+++ /dev/null
@@ -1,74 +0,0 @@
-# This workflow is provided just as an example and not for repo testing/verification
-name: example
-
-on:
-  schedule:
-    - cron: '0 10 * * 0'
-  push:
-    branches:
-      - '**'
-    tags:
-      - 'v*.*.*'
-  pull_request:
-
-env:
-  DOCKER_IMAGE: localhost:5000/name/app
-
-jobs:
-  docker:
-    runs-on: ubuntu-latest
-    services:
-      registry:
-        image: registry:2
-        ports:
-          - 5000:5000
-    steps:
-      -
-        name: Checkout
-        uses: actions/checkout@v3
-      -
-        name: Docker meta
-        id: meta
-        uses: docker/metadata-action@v4
-        with:
-          images: ${{ env.DOCKER_IMAGE }}
-          tags: |
-            type=schedule
-            type=ref,event=branch
-            type=ref,event=pr
-            type=semver,pattern={{version}}
-            type=semver,pattern={{major}}.{{minor}}
-            type=semver,pattern={{major}}
-            type=sha
-      -
-        name: Set up Docker Buildx
-        uses: docker/setup-buildx-action@v2
-        with:
-          driver-opts: network=host
-      -
-        name: Build and export to Docker client
-        uses: ./
-        with:
-          context: ./test
-          file: ./test/Dockerfile
-          load: true
-          tags: ${{ steps.meta.outputs.tags }}
-          labels: ${{ steps.meta.outputs.labels }}
-      -
-        name: Build and push to local registry
-        uses: ./
-        with:
-          context: ./test
-          file: ./test/Dockerfile
-          push: ${{ github.event_name != 'pull_request' }}
-          tags: ${{ steps.meta.outputs.tags }}
-          labels: ${{ steps.meta.outputs.labels }}
-      -
-        name: Inspect image
-        run: |
-          docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }}
-      -
-        name: Check manifest
-        if: github.event_name != 'pull_request'
-        run: |
-          docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }} --format '{{json .}}'

From a3646c08f829bf95ff76c8cb6e6ef2331dcb2506 Mon Sep 17 00:00:00 2001
From: CrazyMax <crazy-max@users.noreply.github.com>
Date: Sun, 9 Apr 2023 06:33:30 +0200
Subject: [PATCH 4/4] test: update go example

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
---
 test/go/Dockerfile | 17 ++++++++++-------
 test/go/go.mod     | 16 ----------------
 test/go/go.sum     | 38 --------------------------------------
 test/go/main.go    | 27 +++++----------------------
 4 files changed, 15 insertions(+), 83 deletions(-)
 delete mode 100644 test/go/go.sum

diff --git a/test/go/Dockerfile b/test/go/Dockerfile
index 2cbcb5d..284345b 100644
--- a/test/go/Dockerfile
+++ b/test/go/Dockerfile
@@ -1,16 +1,19 @@
-FROM golang:1.19-alpine AS base
+# syntax=docker/dockerfile:1
+
+FROM golang:alpine AS base
 ENV CGO_ENABLED=0
 RUN apk add --no-cache file git
 WORKDIR /src
 
-FROM base as build
-COPY go.mod go.sum ./
-RUN go mod download -x
-COPY . .
-RUN go build -ldflags "-s -w" -o /usr/bin/app .
+FROM base AS build
+RUN --mount=type=bind,target=/src \
+    --mount=type=cache,target=/root/.cache/go-build \
+    go build -ldflags "-s -w" -o /usr/bin/app .
 
 FROM scratch AS binary
 COPY --from=build /usr/bin/app /bin/app
 
-FROM alpine:3.17 AS image
+FROM alpine AS image
 COPY --from=build /usr/bin/app /bin/app
+EXPOSE 8080
+ENTRYPOINT ["/bin/app"]
diff --git a/test/go/go.mod b/test/go/go.mod
index cb38f27..956fbc0 100644
--- a/test/go/go.mod
+++ b/test/go/go.mod
@@ -1,19 +1,3 @@
 module github.com/docker/build-push-action/test/go
 
 go 1.18
-
-require github.com/labstack/echo/v4 v4.9.1
-
-require (
-	github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
-	github.com/labstack/gommon v0.4.0 // indirect
-	github.com/mattn/go-colorable v0.1.11 // indirect
-	github.com/mattn/go-isatty v0.0.14 // indirect
-	github.com/valyala/bytebufferpool v1.0.0 // indirect
-	github.com/valyala/fasttemplate v1.2.1 // indirect
-	golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
-	golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
-	golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
-	golang.org/x/text v0.3.7 // indirect
-	golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
-)
diff --git a/test/go/go.sum b/test/go/go.sum
deleted file mode 100644
index a271c33..0000000
--- a/test/go/go.sum
+++ /dev/null
@@ -1,38 +0,0 @@
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
-github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
-github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
-github.com/labstack/echo/v4 v4.9.1 h1:GliPYSpzGKlyOhqIbG8nmHBo3i1saKWFOgh41AN3b+Y=
-github.com/labstack/echo/v4 v4.9.1/go.mod h1:Pop5HLc+xoc4qhTZ1ip6C0RtP7Z+4VzRLWZZFKqbbjo=
-github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
-github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
-github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
-github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
-github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
-github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
-github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
-github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
-golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
-golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
-golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20211103235746-7861aae1554b h1:1VkfZQv42XQlA/jchYumAnv1UPo6RgF9rJFkTgZIxO4=
-golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
-golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
-golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
-golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/test/go/main.go b/test/go/main.go
index 0320cf2..d6199c4 100644
--- a/test/go/main.go
+++ b/test/go/main.go
@@ -1,31 +1,14 @@
 package main
 
 import (
+	"fmt"
+	"log"
 	"net/http"
-	"os"
-
-	"github.com/labstack/echo/v4"
-	"github.com/labstack/echo/v4/middleware"
 )
 
 func main() {
-	e := echo.New()
-
-	e.Use(middleware.Logger())
-	e.Use(middleware.Recover())
-
-	e.GET("/", func(c echo.Context) error {
-		return c.HTML(http.StatusOK, "Hello World")
+	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+		fmt.Fprintf(w, "Hello, Go!")
 	})
-
-	e.GET("/ping", func(c echo.Context) error {
-		return c.JSON(http.StatusOK, struct{ Status string }{Status: "OK"})
-	})
-
-	httpPort := os.Getenv("HTTP_PORT")
-	if httpPort == "" {
-		httpPort = "8080"
-	}
-
-	e.Logger.Fatal(e.Start(":" + httpPort))
+	log.Fatal(http.ListenAndServe(":8080", nil))
 }