From fb6ccbb005bc9a48c7cf27985468da4b41ce3b9b Mon Sep 17 00:00:00 2001 From: Julie Qiu Date: Sat, 17 Jul 2021 10:09:28 -0400 Subject: devtools: add go docker container A docker container is added for running Go code. Change-Id: I1349d28a9fc54f770dda01dcaa6c314674b1e5aa Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/335249 Trust: Julie Qiu Run-TryBot: Julie Qiu TryBot-Result: kokoro Reviewed-by: Jonathan Amsterdam --- devtools/docker/compose.yaml | 11 +++++++++++ devtools/go.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 devtools/go.sh (limited to 'devtools') diff --git a/devtools/docker/compose.yaml b/devtools/docker/compose.yaml index 59f64eac..7b50b556 100644 --- a/devtools/docker/compose.yaml +++ b/devtools/docker/compose.yaml @@ -133,5 +133,16 @@ services: - 3000:3000 environment: - CONNECTION_TIMEOUT=120000 + go: + # This should match the version we are using on AppEngine. + image: golang:1.15.5 + entrypoint: go + environment: + <<: *database-variables + <<: *go-variables + volumes: + - ../../:/pkgsite + - gomodcache:/gomodcache + working_dir: /pkgsite volumes: gomodcache: diff --git a/devtools/go.sh b/devtools/go.sh new file mode 100755 index 00000000..d5285a08 --- /dev/null +++ b/devtools/go.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Copyright 2021 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +source devtools/docker.sh || { echo "Are you at repo root?"; exit 1; } + +set -e + +# Script for running a Go docker image, when go1.15+ is not available locally. +# +# This is can used when Go is not installed on a machine (such as in CI by +# kokoro, which is on go version go1.12 linux/amd64). +#c +# It mounts the pwd into a volume in the container at /pkgsite, +# and sets the working directory in the container to /pkgsite. + +gocmd="dockercompose run go" +if type go > /dev/null; then + # pkgsite requires go1.15 or higher. If that's installed on the machine, just + # use the local go since it will be faster. + # kokoro run go1.12. + # + # This awk program splits the third whitespace-separated field + # (e.g. "go1.15.5") on the dot character and prints the second part. + v=`go version | awk '{split($3, parts, /\./); print parts[2]}'` + if (( v >= 15 )); then + gocmd=go + fi; +fi; + +$gocmd $@ + -- cgit v1.3-6-g1900