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

Updated Dockerfile and makefile to use go 1.5 and cross compile binaries for windows, linux, and osx; updated ConsoleClient README to use docker instructions; Added subheadings (for anchors) to main README

Michael Goldberger 10 лет назад
Родитель
Сommit
3f3a7d044f
5 измененных файлов с 123 добавлено и 62 удалено
  1. 1 0
      ConsoleClient/.gitignore
  2. 12 23
      ConsoleClient/Dockerfile
  3. 41 4
      ConsoleClient/README.md
  4. 52 31
      ConsoleClient/make.bash
  5. 17 4
      README.md

+ 1 - 0
ConsoleClient/.gitignore

@@ -0,0 +1 @@
+bin

+ 12 - 23
ConsoleClient/Dockerfile

@@ -2,36 +2,25 @@
 #
 #
 # See README.md for usage instructions.
 # See README.md for usage instructions.
 
 
-FROM ubuntu:12.04
+FROM ubuntu:15.04
 
 
-ENV GOVERSION=go1.4.1
+ENV GOVERSION=go1.5
 
 
 # Install system-level dependencies.
 # Install system-level dependencies.
 ENV DEBIAN_FRONTEND=noninteractive
 ENV DEBIAN_FRONTEND=noninteractive
-RUN apt-get update && \
-  apt-get -y install build-essential python-software-properties bzip2 unzip curl \
-    git subversion mercurial bzr \
-    upx gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 gcc-multilib
+RUN apt-get update && apt-get -y install build-essential curl git mercurial upx gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 gcc-multilib
 
 
 # Install Go.
 # Install Go.
-ENV GOROOT=/go \
-  GOPATH=/
-ENV PATH=$PATH:$GOROOT/bin
-RUN echo "INSTALLING GO" && \
-  curl -L https://github.com/golang/go/archive/$GOVERSION.zip -o /tmp/go.zip && \
-  unzip /tmp/go.zip && \
-  rm /tmp/go.zip && \
-  mv /go-$GOVERSION $GOROOT && \
-  echo $GOVERSION > $GOROOT/VERSION && \
-  cd $GOROOT/src && \
-  ./all.bash
+ENV GOROOT=/usr/local/go GOPATH=/go
+ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
+
+RUN curl -L https://storage.googleapis.com/golang/$GOVERSION.linux-amd64.tar.gz -o /tmp/go.tar.gz && \
+  tar -C /usr/local -xzf /tmp/go.tar.gz && \
+  rm /tmp/go.tar.gz && \
+  echo $GOVERSION > $GOROOT/VERSION
 
 
 ENV CGO_ENABLED=1
 ENV CGO_ENABLED=1
-RUN go get github.com/mitchellh/gox && \
-  go get github.com/inconshreveable/gonative && \
-  mkdir -p /usr/local/gonative && \
-  cd /usr/local/gonative && \
-  gonative build
-ENV PATH=/usr/local/gonative/go/bin:$PATH
+
+RUN go get github.com/mitchellh/gox && go get github.com/pwaller/goupx
 
 
 WORKDIR $GOPATH/src
 WORKDIR $GOPATH/src

+ 41 - 4
ConsoleClient/README.md

@@ -1,6 +1,43 @@
-Psiphon Console Client README
-================================================================================
+##Psiphon Console Client README
 
 
-### Setup
+###Building with Docker
 
 
-See: https://github.com/Psiphon-Labs/psiphon-tunnel-core#setup
+Note that you may need to use `sudo docker` below, depending on your OS.
+
+#####Create the build image:
+  1. Run the command: `docker build --no-cache=true -t psiclient .` (this may take some time to complete)
+  2. Once completed, verify that you see an image named `psiclient` when running: `docker images`
+
+#####Run the build:
+
+  ```bash
+  cd .. && \
+    docker run \
+    --rm \
+    -v $(pwd):/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core \
+    psiclient \
+    /bin/bash -c 'cd /go/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient && ./make.bash' \
+  && cd -
+  ```
+
+When that command completes, the compiled binaries will be located in the `bin` directory under the current directory. The structure will be:
+  ```
+  bin
+  ├── darwin
+  │   └── psiphon-native-messaging-host-x86_64
+  ├── linux
+  │   └── psiphon-native-messaging-host-i686
+  │   └── psiphon-native-messaging-host-x86_64
+  └── windows
+      └── psiphon-native-messaging-host-i686.exe
+      └── psiphon-native-messaging-host-x86_64.exe
+
+  ```
+
+### Building without Docker
+
+See the [main README build section](../README.md#build)
+
+### Creating a configuration file
+
+See the [main README configuration section](../README.md#configure)

+ 52 - 31
ConsoleClient/make.bash

@@ -1,49 +1,70 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
 set -e
 set -e
-set -exv # verbose output for testing
 
 
 if [ ! -f make.bash ]; then
 if [ ! -f make.bash ]; then
-  echo 'make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient'
+  echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient"
   exit 1
   exit 1
 fi
 fi
 
 
-CGO_ENABLED=1
-
-# Make sure we have our dependencies
-echo -e "go-getting dependencies...\n"
-go get -d -v ./...
-
 EXE_BASENAME="psiphon-tunnel-core"
 EXE_BASENAME="psiphon-tunnel-core"
 BUILDINFOFILE="${EXE_BASENAME}_buildinfo.txt"
 BUILDINFOFILE="${EXE_BASENAME}_buildinfo.txt"
 BUILDDATE=$(date --iso-8601=seconds)
 BUILDDATE=$(date --iso-8601=seconds)
 BUILDREPO=$(git config --get remote.origin.url)
 BUILDREPO=$(git config --get remote.origin.url)
-BUILDREV=$(git rev-parse HEAD)
+BUILDREV=$(git rev-parse --short HEAD)
+
 LDFLAGS="\
 LDFLAGS="\
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildDate $BUILDDATE \
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildDate $BUILDDATE \
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRepo $BUILDREPO \
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRepo $BUILDREPO \
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRev $BUILDREV \
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRev $BUILDREV \
 "
 "
 echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
 echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
-echo -e "LDFLAGS=$LDFLAGS\n"
-
-echo -e "\nBuilding windows-386..."
-CC=/usr/bin/i686-w64-mingw32-gcc \
-  gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output windows_386_${EXE_BASENAME}
-# We are finding that UPXing the full Windows Psiphon client produces better results
-# if psiphon-tunnel-core.exe is not already UPX'd.
-#upx --best windows_386_${EXE_BASENAME}.exe
-
-echo -e "\nBuilding windows-amd64..."
-CC=/usr/bin/x86_64-w64-mingw32-gcc \
-  gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output windows_amd64_${EXE_BASENAME}
-upx --best windows_amd64_${EXE_BASENAME}.exe
-
-echo -e "\nBuilding linux-amd64..."
-gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output linux_amd64_${EXE_BASENAME}
-upx --best linux_amd64_${EXE_BASENAME}
-
-echo -e "\nBuilding linux-386..."
-CFLAGS=-m32 \
-  gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output linux_386_${EXE_BASENAME}
-upx --best linux_386_${EXE_BASENAME}
+
+echo "Variables for ldflags:"
+echo " Build date: ${BUILDDATE}"
+echo " Build repo: ${BUILDREPO}"
+echo " Build revision: ${BUILDREV}"
+echo ""
+
+echo "Getting project dependencies (via go get)"
+GOOS=linux go get -d -v ./...
+GOOS=windows go get -d -v ./...
+GOOS=darwin go get -d -v ./...
+
+if [ ! -d bin ]; then
+  mkdir bin
+fi
+
+# Windows requires CGO due to sqlite. OpenSSL will likely eventually require CGO everywhere
+echo "CGO Enabled"
+export CGO_ENABLED=1
+
+echo "Building windows-i686..."
+CC=/usr/bin/i686-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
+# We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
+echo "..No UPX for this build"
+
+echo "Building windows-x86_64..."
+CC=/usr/bin/x86_64-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
+# We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
+echo "..No UPX for this build"
+
+echo "CGO Enabled unset (Preferred unless needed)"
+unset CGO_ENABLED
+
+echo "Building linux-i686..."
+CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
+echo "..UPX packaging output"
+goupx --best bin/linux/${EXE_BASENAME}-i686
+
+echo "Building linux-x86_64..."
+gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
+echo "..UPX packaging output"
+goupx --best bin/linux/${EXE_BASENAME}-x86_64
+
+echo "Building darwin-x86_64..."
+gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
+# Darwin binaries don't seem to be UPXable when built this way
+echo "..No UPX for this build"
+
+echo "Done"

+ 17 - 4
README.md

@@ -18,6 +18,8 @@ This project is currently at the proof-of-concept stage. Current production Psip
 Setup
 Setup
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
 
 
+#### Build
+
 * Go 1.4 (or higher) is required.
 * Go 1.4 (or higher) is required.
 * This project builds and runs on recent versions of Windows, Linux, and Mac OS X.
 * This project builds and runs on recent versions of Windows, Linux, and Mac OS X.
 * Note that the `psiphon` package is imported using the absolute path `github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon`; without further local configuration, `go` will use this version of the code and not the local copy in the repository.
 * Note that the `psiphon` package is imported using the absolute path `github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon`; without further local configuration, `go` will use this version of the code and not the local copy in the repository.
@@ -35,9 +37,10 @@ Setup
     "
     "
     ```
     ```
 
 
-* Run `./ConsoleClient --config psiphon.config` where the config file looks like this:
+#### Configure
+
+ * Configuration files are standard text files containing a valid JSON object. Example:
 
 
-  <!--BEGIN-SAMPLE-CONFIG-->
   ```
   ```
   {
   {
       "PropagationChannelId" : "<placeholder>",
       "PropagationChannelId" : "<placeholder>",
@@ -46,12 +49,22 @@ Setup
       "LocalSocksProxyPort" : 1080
       "LocalSocksProxyPort" : 1080
   }
   }
   ```
   ```
-  <!--END-SAMPLE-CONFIG-->
 
 
-* Config file parameters are [documented here](https://godoc.org/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon#Config).
+* All config file parameters are [documented here](https://godoc.org/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon#Config).
 * Replace each `<placeholder>` with a value from your Psiphon network. The Psiphon server-side stack is open source and can be found in our  [Psiphon 3 repository](https://bitbucket.org/psiphon/psiphon-circumvention-system). If you would like to use the Psiphon Inc. network, contact <developer-support@psiphon.ca>.
 * Replace each `<placeholder>` with a value from your Psiphon network. The Psiphon server-side stack is open source and can be found in our  [Psiphon 3 repository](https://bitbucket.org/psiphon/psiphon-circumvention-system). If you would like to use the Psiphon Inc. network, contact <developer-support@psiphon.ca>.
+
+
+#### Run
+
+* Run `./ConsoleClient --config psiphon.config` where `psiphon.config` is created as described in the [Configure](#configure) section above
+
+
+Other Platforms
+--------------------------------------------------------------------------------
+
 * The project builds and runs on Android. See the [AndroidLibrary README](AndroidLibrary/README.md) for more information about building the Go component, and the [AndroidApp README](AndroidApp/README.md) for a sample Android app that uses it.
 * The project builds and runs on Android. See the [AndroidLibrary README](AndroidLibrary/README.md) for more information about building the Go component, and the [AndroidApp README](AndroidApp/README.md) for a sample Android app that uses it.
 
 
+
 Licensing
 Licensing
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------