Skip to content

Commit 92cee07

Browse files
committed
vcs-test: fix deployment and systemd socket association
Quoting https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances under "Best Practices": > Grant the instance the https://www.googleapis.com/auth/cloud-platform > scope to allow full access to all Google Cloud APIs, so that the IAM > permissions of the instance are completely determined by the IAM roles > of the service account. Updates golang/go#27127 Change-Id: Icceb3b17a12223199efd67d27f6bca2b71f8fadc Reviewed-on: https://go-review.googlesource.com/130475 Reviewed-by: Andrew Bonventre <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 0cb088d commit 92cee07

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

vcs-test/rebuild-server.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gcloud compute instances create vcs-test --zone=us-central1-a \
1111
--image-project debian-cloud --image-family debian-9 \
1212
--machine-type n1-standard-1 \
1313
--service-account=vcs-test@symbolic-datum-552.iam.gserviceaccount.com \
14+
--scopes cloud-platform \
1415
--tags=allow-ssh,http-server,https-server
1516

1617
while sleep 5 && ! gcloud compute ssh vcs-test -- date; do
@@ -20,7 +21,7 @@ done
2021
gcloud compute ssh vcs-test -- sudo -n bash -c \''
2122
mkdir -p /home/vcweb/svn
2223
chown -R uucp:uucp /home/vcweb
23-
chown -R 777 /home/vcweb
24+
chmod -R 777 /home/vcweb
2425
apt-get update
2526
apt-get install -y mercurial fossil bzr git apache2 ed subversion libapache2-mod-svn
2627
perl -pie 's/80/8888/' /etc/apache2/ports.conf

vcs-test/redeploy-vcweb.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
set -e
77

88
info="$USER $(date)"
9-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "-ldflags=\"-X=main.buildInfo=$info\"" -o vcweb.exe ./vcweb
9+
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "-ldflags=\"-X=main.buildInfo=$info\"" -o vcweb.exe ./vcweb
1010
trap "rm -f vcweb.exe" EXIT
1111

1212
gcloud beta compute scp vcweb.exe vcs-test:
1313

1414
gcloud compute ssh vcs-test -- sudo -n bash -c \''
1515
mv vcweb.exe /usr/bin/vcweb
16+
chmod a+rx /usr/bin/vcweb
1617
systemctl restart vcweb.service
1718
systemctl status -l vcweb.service
1819
'\'

vcs-test/vcweb/main.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,12 @@ func main() {
6969
handler := logger(http.HandlerFunc(loadAndHandle))
7070

7171
// If running under systemd, listen on 80 and 443 and serve TLS.
72-
if listeners, _ := activation.Listeners(); len(listeners) == 2 {
73-
// Want listeners[0] is port 80, listeners[1] is port 443.
74-
// There's no guaranteed order of the listeners!
75-
// Sometimes we get 80, 443; other times we get 443, 80.
76-
names := strings.Split(os.Getenv("LISTEN_FDNAMES"), ":")
77-
if strings.Contains(names[0], "https") {
78-
listeners[0], listeners[1] = listeners[1], listeners[0]
79-
}
72+
if listeners, _ := activation.ListenersWithNames(); len(listeners) == 2 {
73+
httpListener := listeners["vcweb-http.socket"][0]
74+
httpsListener := listeners["vcweb-https.socket"][0]
8075

8176
go func() {
82-
log.Fatal(http.Serve(listeners[0], handler))
77+
log.Fatal(http.Serve(httpListener, handler))
8378
}()
8479
dir := acme.LetsEncryptURL
8580
if *staging {
@@ -115,7 +110,7 @@ func main() {
115110
daemon.SdNotify(false, "WATCHDOG=1")
116111
}
117112
}()
118-
log.Fatal(s.ServeTLS(listeners[1], "", ""))
113+
log.Fatal(s.ServeTLS(httpsListener, "", ""))
119114
}
120115

121116
// Local development on :8088.

0 commit comments

Comments
 (0)