From 3002e623d3746085e8fc6f111c53406e5b3203e3 Mon Sep 17 00:00:00 2001
From: Jim Zhang <jim.zhang@kaleido.io>
Date: Thu, 25 Jan 2024 16:09:04 -0500
Subject: [PATCH 1/2] Add docker build to PR builds; fix paths in Dockerfile

Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
---
 .github/workflows/go.yml | 20 +++++++++++++++++++-
 Dockerfile               |  8 ++------
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index a2410ca..4aa401b 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -16,7 +16,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v4
         with:
-          go-version: "1.21"
+          go-version: '1.21'
           check-latest: true
 
       - name: Build and Test
@@ -24,3 +24,21 @@ jobs:
 
       - name: Upload coverage
         run: bash <(curl -s https://codecov.io/bash)
+  docker:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Set up Go
+        uses: actions/setup-go@v4
+        with:
+          go-version: '1.21'
+          check-latest: true
+
+      - name: Build
+        run: |
+          docker build \
+            --label commit=$GITHUB_SHA \
+            --label build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
+            --label tag=${{ steps.build_tag_generator.outputs.BUILD_TAG }} \
+            --tag ghcr.io/hyperledger/firefly-fabconnect:${{ steps.build_tag_generator.outputs.BUILD_TAG }} .
diff --git a/Dockerfile b/Dockerfile
index fb712bd..4890064 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,19 +1,15 @@
 FROM golang:1.21-alpine3.19 AS fabconnect-builder
 RUN apk add make
-ADD --chown=1001:0 . /fabconnect
+ADD . /fabconnect
 WORKDIR /fabconnect
 RUN mkdir /.cache \
     && chgrp -R 0 /.cache \
     && chmod -R g+rwX /.cache
-USER 1001
 RUN make
 
 FROM alpine:3.19
 WORKDIR /fabconnect
-COPY --from=fabconnect-builder --chown=1001:0 /fabconnect/fabconnect ./
+COPY --from=fabconnect-builder /fabconnect/fabconnect ./
 ADD ./openapi ./openapi/
 RUN ln -s /fabconnect/fabconnect /usr/bin/fabconnect
-RUN chgrp -R 0 /openapi && \
-    chmod -R g+rwX /openapi
-USER 1001
 ENTRYPOINT [ "fabconnect" ]

From 6359310cb30fb648900018cb2cc0169a935afdac Mon Sep 17 00:00:00 2001
From: Jim Zhang <jim.zhang@kaleido.io>
Date: Thu, 25 Jan 2024 16:15:17 -0500
Subject: [PATCH 2/2] Fix github action for docker build

Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
---
 .github/workflows/go.yml | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 4aa401b..359e75b 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -29,11 +29,12 @@ jobs:
     steps:
       - uses: actions/checkout@v4
 
-      - name: Set up Go
-        uses: actions/setup-go@v4
-        with:
-          go-version: '1.21'
-          check-latest: true
+      - name: Set build tag
+        id: build_tag_generator
+        run: |
+          RELEASE_TAG=$(curl https://api.github.com/repos/hyperledger/firefly-fabconnect/releases/latest -s | jq .tag_name -r)
+          BUILD_TAG=$RELEASE_TAG-$(date +"%Y%m%d")-$GITHUB_RUN_NUMBER
+          echo ::set-output name=BUILD_TAG::$BUILD_TAG
 
       - name: Build
         run: |