Просмотр исходного кода

added docker container and make.bash for building psiphond within a container (look into nesting containers via onbuild to flatten); updated README to show usage of new container plus setting ip to 0.0.0.0 when generating a config

Michael Goldberger 9 лет назад
Родитель
Сommit
a7136fa9e5
3 измененных файлов с 68 добавлено и 1 удалено
  1. 28 0
      Server/Dockerfile-binary-builder
  2. 9 1
      Server/README.md
  3. 31 0
      Server/make.bash

+ 28 - 0
Server/Dockerfile-binary-builder

@@ -0,0 +1,28 @@
+FROM alpine:latest
+
+ENV GOLANG_VERSION 1.6.2
+ENV GOLANG_SRC_URL https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz
+
+RUN set -ex \
+	&& apk add --no-cache \
+		bash \
+		ca-certificates \
+		gcc \
+    git \
+		musl-dev \
+		openssl \
+		go \
+	\
+	&& export GOROOT_BOOTSTRAP="$(go env GOROOT)" \
+	\
+	&& wget -q "$GOLANG_SRC_URL" -O golang.tar.gz \
+	&& tar -C /usr/local -xzf golang.tar.gz \
+	&& rm golang.tar.gz \
+	&& cd /usr/local/go/src \
+	&& ./make.bash
+
+ENV GOPATH /go
+ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
+
+RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
+WORKDIR $GOPATH

+ 9 - 1
Server/README.md

@@ -32,9 +32,17 @@ Build Steps:
  - Get dependencies: `GOOS=linux GOARCH=amd64 go get -d -v ./...`
  - Build: `GOOS=linux GOARCH=amd64 CC=/usr/local/musl/bin/musl-gcc go build --ldflags '-linkmode external -extldflags "-static"' -o psiphond main.go` (will generate a statically linked binary named `psiphond`)
 
+##### Building the binary with MUSL in Docker
+
+You may also use the `Dockerfile-binary-builder` docker file to create an image that will be able to build the binary for you without installing MUSL and cross-compiling locally.
+
+1. Build the image: `docker build -f Dockerfile-binary-builder -t psiphond-builder .`
+2. Run the build via the image: `cd .. && docker run --rm -v $(pwd):/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core psiphond-builder /bin/bash -c 'cd /go/src/github.com/Psiphon-Labs/psiphon-tunnel-core/Server && ./make.bash'; cd -`
+3. Change the owner (if desired) of the `psiphond` binary. The permissions are `777`/`a+rwx`, but the owner and group will both be `root`. Functionally, this should not matter at all.
+
 ##### Generate a configuration file
  1. Use the command `./psiphond --help` to get a list of flags to pass to the `generate` sub-command
- 2. Run: `./psiphond --newConfig psiphond.config --protocol SSH:22 --protocol OSSH:53 --web 80 generate`
+ 2. Run: `./psiphond --newConfig psiphond.config --ipaddress 0.0.0.0 --protocol SSH:22 --protocol OSSH:53 --web 80 generate` (IP address `0.0.0.0` is used due to how docker handles services bound to the loopback device)
  3. Remove the value for the `SyslogFacility` key (eg: `sed -i 's/"SyslogFacility": "user"/"SyslogFacility": ""/' psiphond.config`)
  4. Remove the value for the `Fail2BanFormat` key (eg: `sed -i 's/"Fail2BanFormat": "Authentication failure for psiphon-client from %s"/"Fail2BanFormat": ""/' psiphond.config`)
 

+ 31 - 0
Server/make.bash

@@ -0,0 +1,31 @@
+#!/usr/bin/env sh
+
+set -e
+
+BASE_DIR=$( cd "$(dirname "$0")" ; pwd -P )
+cd $BASE_DIR
+
+if [ ! -f make.bash ]; then
+  echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/Server"
+  exit 1
+fi
+
+build_for_linux () {
+  echo "Getting project dependencies (via go get) for Linux. Parameter is: '$1'"
+  GOOS=linux GOARCH=amd64 go get -d -v ./...
+  if [ $? != 0 ]; then
+    echo "...'go get' failed, exiting"
+    exit $?
+  fi
+
+  GOOS=linux GOARCH=amd64 go build --ldflags '-linkmode external -extldflags "-static"' -o psiphond main.go
+  if [ $? != 0 ]; then
+    echo "...'go build' failed, exiting"
+    exit $?
+  fi
+  chmod 777 psiphond
+
+}
+
+build_for_linux
+echo "Done"