This is an automated email from the ASF dual-hosted git repository.

zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 40e7d68e25 Use golang docker image (#7266)
40e7d68e25 is described below

commit 40e7d68e25a2224f8aec2732c5d95b5836edd752
Author: Eric Holguin <[email protected]>
AuthorDate: Mon Jan 9 10:07:07 2023 -0700

    Use golang docker image (#7266)
    
    * use golang docker image
    
    * use realtive path sym links
    
    * fix order
    
    * add .env file
    
    * use alpine version and remove extra back slash
---
 tools/golang/.env                                      |  1 +
 tools/golang/Dockerfile                                | 18 +++++++-----------
 tools/golang/docker-compose.yml                        |  4 ++++
 traffic_monitor/tests/.env                             |  1 +
 traffic_monitor/tests/Dockerfile-golangtest            | 15 ++++++---------
 traffic_monitor/tests/_integration/.env                |  1 +
 traffic_monitor/tests/_integration/Dockerfile          | 16 +++++++---------
 traffic_monitor/tests/_integration/docker-compose.yml  |  2 ++
 traffic_monitor/tests/docker-compose.yml               |  2 ++
 traffic_ops/app/bin/tests/.env                         |  1 +
 traffic_ops/app/bin/tests/Dockerfile-golangtest        | 15 ++++++---------
 traffic_ops/app/bin/tests/docker-compose.yml           |  2 ++
 traffic_ops/traffic_ops_golang/swaggerdocs/v13/.env    |  1 +
 .../traffic_ops_golang/swaggerdocs/v13/Dockerfile      | 18 ++++++++----------
 .../swaggerdocs/v13/docker-compose.yml                 |  2 ++
 15 files changed, 51 insertions(+), 48 deletions(-)

diff --git a/tools/golang/.env b/tools/golang/.env
new file mode 120000
index 0000000000..c7360fb82d
--- /dev/null
+++ b/tools/golang/.env
@@ -0,0 +1 @@
+../../.env
\ No newline at end of file
diff --git a/tools/golang/Dockerfile b/tools/golang/Dockerfile
index 8ce94a6101..617405a083 100644
--- a/tools/golang/Dockerfile
+++ b/tools/golang/Dockerfile
@@ -15,24 +15,20 @@
 # specific language governing permissions and limitations
 # under the License.
 
+ARG GO_VERSION
+FROM golang:${GO_VERSION}-alpine AS get-go
 FROM alpine:3.13 AS base
 
-COPY GO_VERSION /
+COPY --from=get-go /usr/local/go /usr/local/go
+ENV PATH=/usr/local/go/bin:${PATH} \
+    GOPATH=/go
+
 RUN set -o errexit; \
-    go_version=$(cat /GO_VERSION); \
-    wget -O go.tar.gz 
https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz; \
-    tar -C /usr/local -xvzf go.tar.gz; \
-    ln -s /usr/local/go/bin/go /usr/bin/go; \
-    rm go.tar.gz; \
     architecture=$(uname -m); \
     mkdir lib64; \
     # Use musl libc where the go binary expects glibc
     # Less-generalized: ln -s /lib/ld-musl-x86_64.so.1 
/lib64/ld-linux-x86-64.so.2
-    ln -s /lib/ld-musl-${architecture}.so.[0-9] 
/lib64/ld-linux-${architecture//_/-}.so.2; \
-    # Test the go binary
-    go version
-ENV GOPATH=/go
-ENV PATH="${PATH}:${GOPATH}/bin"
+    ln -s /lib/ld-musl-${architecture}.so.[0-9] 
/lib64/ld-linux-${architecture//_/-}.so.2;
 
 RUN apk --no-cache add gcc musl-dev git
 
diff --git a/tools/golang/docker-compose.yml b/tools/golang/docker-compose.yml
index bbfc409142..854db7b3ad 100644
--- a/tools/golang/docker-compose.yml
+++ b/tools/golang/docker-compose.yml
@@ -23,6 +23,8 @@ services:
       context: ../..
       dockerfile: tools/golang/Dockerfile
       target: lint
+      args:
+        - GO_VERSION=${GO_VERSION}
     volumes:
       - ../..:/go/src/github.com/apache/trafficcontrol
 
@@ -31,6 +33,8 @@ services:
       context: ../..
       dockerfile: tools/golang/Dockerfile
       target: unit
+      args:
+        - GO_VERSION=${GO_VERSION}
     volumes:
       - ../..:/go/src/github.com/apache/trafficcontrol
       - ./junit:/junit
diff --git a/traffic_monitor/tests/.env b/traffic_monitor/tests/.env
new file mode 120000
index 0000000000..c7360fb82d
--- /dev/null
+++ b/traffic_monitor/tests/.env
@@ -0,0 +1 @@
+../../.env
\ No newline at end of file
diff --git a/traffic_monitor/tests/Dockerfile-golangtest 
b/traffic_monitor/tests/Dockerfile-golangtest
index cb4228d06a..2daa2709e9 100644
--- a/traffic_monitor/tests/Dockerfile-golangtest
+++ b/traffic_monitor/tests/Dockerfile-golangtest
@@ -11,8 +11,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+ARG GO_VERSION
+FROM golang:${GO_VERSION} AS get-go
 FROM debian:buster
 
+COPY --from=get-go /usr/local/go /usr/local/go
+ENV PATH=/usr/local/go/bin:${PATH} \
+    GOPATH=/go
+
 RUN apt-get update && \
     apt-get install -y --no-install-recommends \
         ca-certificates \
@@ -24,15 +30,6 @@ RUN apt-get update && \
         wget && \
     apt-get clean
 
-COPY GO_VERSION /
-RUN go_version=$(cat /GO_VERSION) && \
-    wget -O go.tar.gz 
https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz && \
-    tar -C /usr/local -xvzf go.tar.gz && \
-    ln -s /usr/local/go/bin/go /usr/bin/go && \
-    rm go.tar.gz
-ENV GOPATH=/go
-ENV PATH="${PATH}:${GOPATH}/bin"
-
 ARG DIR=github.com/apache/trafficcontrol
 
 ADD traffic_monitor /go/src/$DIR/traffic_monitor
diff --git a/traffic_monitor/tests/_integration/.env 
b/traffic_monitor/tests/_integration/.env
new file mode 120000
index 0000000000..e72b3932f4
--- /dev/null
+++ b/traffic_monitor/tests/_integration/.env
@@ -0,0 +1 @@
+../../../.env
\ No newline at end of file
diff --git a/traffic_monitor/tests/_integration/Dockerfile 
b/traffic_monitor/tests/_integration/Dockerfile
index 0aec84d77a..b3de64f535 100644
--- a/traffic_monitor/tests/_integration/Dockerfile
+++ b/traffic_monitor/tests/_integration/Dockerfile
@@ -20,20 +20,18 @@
 # It doesn't do any of the complex things the Dockerfiles in 
infrastructure/docker or infrastructure/cdn-in-a-box do, like inserting itself 
into Traffic Ops.
 # It is designed for a very simple use case, where the complex orchestration 
of other Traffic Control components is done elsewhere (or manually).
 
+ARG GO_VERSION
+FROM golang:${GO_VERSION} AS get-go
 FROM rockylinux:8
 MAINTAINER [email protected]
 
-RUN dnf install -y initscripts epel-release jq git
-COPY GO_VERSION .
-RUN go_version=$(cat /GO_VERSION) && \
-       curl -Lo go.tar.gz 
https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz && \
-       tar -C /usr/local -xzf go.tar.gz && \
-       ln -s /usr/local/go/bin/go /usr/bin/go && \
-       rm go.tar.gz GO_VERSION
-
-ENV GOPATH=/go \
+COPY --from=get-go /usr/local/go /usr/local/go
+ENV PATH=/usr/local/go/bin:${PATH} \
+    GOPATH=/go \
     CGO_ENABLED=0
 
+RUN dnf install -y initscripts epel-release jq git
+
 COPY traffic_monitor/tests/_integration/ /tm/
 
 RUN mkdir -p ${GOPATH}/src/github.com/apache/trafficcontrol
diff --git a/traffic_monitor/tests/_integration/docker-compose.yml 
b/traffic_monitor/tests/_integration/docker-compose.yml
index 95754954e4..fdd2f0dd44 100644
--- a/traffic_monitor/tests/_integration/docker-compose.yml
+++ b/traffic_monitor/tests/_integration/docker-compose.yml
@@ -82,6 +82,8 @@ services:
     build:
       context: ../../..
       dockerfile: traffic_monitor/tests/_integration/Dockerfile
+      args:
+        - GO_VERSION=${GO_VERSION}
     depends_on:
       - testto
       - testcaches
diff --git a/traffic_monitor/tests/docker-compose.yml 
b/traffic_monitor/tests/docker-compose.yml
index 2ed9a42547..7d7f6be8b0 100644
--- a/traffic_monitor/tests/docker-compose.yml
+++ b/traffic_monitor/tests/docker-compose.yml
@@ -26,6 +26,8 @@ services:
     build:
       context: ../..
       dockerfile: traffic_monitor/tests/Dockerfile-golangtest
+      args:
+        - GO_VERSION=${GO_VERSION}
     volumes:
       - traffic_monitor:/traffic_monitor
       - ../../junit:/junit
diff --git a/traffic_ops/app/bin/tests/.env b/traffic_ops/app/bin/tests/.env
new file mode 120000
index 0000000000..8023cca107
--- /dev/null
+++ b/traffic_ops/app/bin/tests/.env
@@ -0,0 +1 @@
+../../../../.env
\ No newline at end of file
diff --git a/traffic_ops/app/bin/tests/Dockerfile-golangtest 
b/traffic_ops/app/bin/tests/Dockerfile-golangtest
index fc6da7985a..aa7a1ac9e9 100644
--- a/traffic_ops/app/bin/tests/Dockerfile-golangtest
+++ b/traffic_ops/app/bin/tests/Dockerfile-golangtest
@@ -11,10 +11,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+ARG GO_VERSION
+FROM golang:${GO_VERSION} AS get-go
 FROM debian:buster
 MAINTAINER [email protected]
 ARG DIR=github.com/apache/trafficcontrol
 
+COPY --from=get-go /usr/local/go /usr/local/go
+ENV PATH=/usr/local/go/bin:${PATH} \
+    GOPATH=/go
+
 RUN apt-get update && \
     apt-get install -y --no-install-recommends \
         ca-certificates \
@@ -25,15 +31,6 @@ RUN apt-get update && \
         wget && \
     apt-get clean
 
-COPY GO_VERSION /
-RUN go_version=$(cat /GO_VERSION) && \
-    wget -qO go.tar.gz 
https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz && \
-    tar -C /usr/local -xvzf go.tar.gz && \
-    ln -s /usr/local/go/bin/go /usr/bin/go && \
-    rm go.tar.gz
-ENV GOPATH=/go
-ENV PATH="${PATH}:${GOPATH}/bin"
-
 ADD traffic_ops /go/src/$DIR/traffic_ops
 ADD lib /go/src/$DIR/lib
 ADD traffic_monitor /go/src/$DIR/traffic_monitor
diff --git a/traffic_ops/app/bin/tests/docker-compose.yml 
b/traffic_ops/app/bin/tests/docker-compose.yml
index 1926ea03b1..5526a637d2 100644
--- a/traffic_ops/app/bin/tests/docker-compose.yml
+++ b/traffic_ops/app/bin/tests/docker-compose.yml
@@ -25,6 +25,8 @@ services:
     build:
       context: ../../../..
       dockerfile: traffic_ops/app/bin/tests/Dockerfile-golangtest
+      args:
+        - GO_VERSION=${GO_VERSION}
     volumes:
       - traffic_ops_golang:/traffic_ops_golang
 
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/.env 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/.env
new file mode 120000
index 0000000000..8023cca107
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/.env
@@ -0,0 +1 @@
+../../../../.env
\ No newline at end of file
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/Dockerfile 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/Dockerfile
index 0b0f128095..5d78fcfc7e 100644
--- a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/Dockerfile
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/Dockerfile
@@ -15,10 +15,17 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
- 
+
+ARG GO_VERSION
+FROM golang:${GO_VERSION} AS get-go
+
 #  Swagger Spec Server
 FROM debian:buster AS swagger-server
 
+COPY --from=get-go /usr/local/go /usr/local/go
+ENV PATH=/usr/local/go/bin:${PATH} \
+    GOPATH=/go
+
 RUN apt-get update && \
     apt-get install -y --no-install-recommends \
         ca-certificates \
@@ -26,15 +33,6 @@ RUN apt-get update && \
         wget && \
     apt-get clean
 
-COPY GO_VERSION /
-RUN go_version=$(cat /GO_VERSION) && \
-    wget -O go.tar.gz 
https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz && \
-    tar -C /usr/local -xvzf go.tar.gz && \
-    ln -s /usr/local/go/bin/go /usr/bin/go && \
-    rm go.tar.gz
-ENV GOPATH=/go
-
-
 COPY traffic_ops/traffic_ops_golang/swaggerdocs/v13/swaggerspec .
 COPY traffic_ops/traffic_ops_golang/swaggerdocs/v13/swaggerspec-server 
/usr/src/swaggerspec-server
 WORKDIR /usr/src/swaggerspec-server
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker-compose.yml 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker-compose.yml
index 172ba0cdff..63f4fd570d 100644
--- a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker-compose.yml
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker-compose.yml
@@ -23,6 +23,8 @@ services:
      build:
        context: ../../../..
        dockerfile: traffic_ops/traffic_ops_golang/swaggerdocs/v13/Dockerfile
+       args:
+         - GO_VERSION=${GO_VERSION}
      ports:
        - 8000:8000
      volumes:

Reply via email to