From 872e1cc23f45139f8d7edda4a47d6845a22c77d7 Mon Sep 17 00:00:00 2001
From: Recolic K <bensl@microsoft.com>
Date: Wed, 26 May 2021 14:26:57 +0800
Subject: [PATCH] dockerfile

---
 .gitignore              |  1 +
 Dockerfile              | 13 +++++++++++++
 main.go                 |  2 +-
 tools/build-and-pack.sh | 12 ++++++++----
 4 files changed, 23 insertions(+), 5 deletions(-)
 create mode 100644 Dockerfile

diff --git a/.gitignore b/.gitignore
index e3c41d0..031b027 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 
 openxt
 *.tar.gz
+bin/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..ae470e6
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,13 @@
+######## Docker build guide
+# tools/build-and-pack.sh linux64-only
+# sudo docker build -f Dockerfile -t recolic/openxt .
+
+# Requires dotnet-core 5.0.x. dotnet 3.x can not build .net framework project. 
+from mcr.microsoft.com/dotnet/sdk:5.0
+
+copy *.tar.gz /tmp
+run cd /tmp && tar xvzf openxt*.tar.gz && cp bin/* /usr/bin/
+run openxt || echo ""
+
+
+
diff --git a/main.go b/main.go
index 7d158bd..1cec377 100644
--- a/main.go
+++ b/main.go
@@ -10,7 +10,7 @@ import (
 // Some options here. Would be improved in beta release.
 const DEDUCT_PKGNAME_FROM_VARNAME = true
 const USE_PROJECT_NETVER_INSTEAD_OF_HINTPATH_NETVER = false
-const OPENXT_VERSION = "1.3-1"
+const OPENXT_VERSION = "1.3-2"
 
 func print_help_and_exit() {
 	println("Usage: openxt <subcommand> [options...]")
diff --git a/tools/build-and-pack.sh b/tools/build-and-pack.sh
index cb21959..b847317 100755
--- a/tools/build-and-pack.sh
+++ b/tools/build-and-pack.sh
@@ -11,12 +11,15 @@ function build () {
     arch="$2"
     echo "Building OpenXT $version for $os:$arch ..."
 
-    [[ "$os" = "windows" ]] && bin_tail=".exe" || bin_tail=""
+    [[ "$os" = windows ]] && bin_tail=".exe" || bin_tail=""
     rm -rf bin/
 
-    GOOS="$os" GOARCH="$arch" go build -o "bin/openxt$bin_tail" . &&
-    GOOS="$os" GOARCH="$arch" go build -o "bin/csproj-to-5$bin_tail" tools/csproj-to-5/main.go &&
-    GOOS="$os" GOARCH="$arch" go build -o "bin/nuget-download-package$bin_tail" tools/nuget-download-package/main.go tools/nuget-download-package/unzip.go &&
+    # Static compilation for linux
+    [[ "$os" = linux ]] && xtra_flags=(-ldflags '-extldflags "-static"') && export CGO_ENABLED=0 || xtra_flags=()
+
+    GOOS="$os" GOARCH="$arch" go build "${xtra_flags[@]}" -o "bin/openxt$bin_tail" . &&
+    GOOS="$os" GOARCH="$arch" go build "${xtra_flags[@]}" -o "bin/csproj-to-5$bin_tail" tools/csproj-to-5/main.go &&
+    GOOS="$os" GOARCH="$arch" go build "${xtra_flags[@]}" -o "bin/nuget-download-package$bin_tail" tools/nuget-download-package/main.go tools/nuget-download-package/unzip.go &&
     tar cvzf "openxt-$version-$os-$arch.tar.gz" bin
 
     return $?
@@ -24,6 +27,7 @@ function build () {
 
 # Just add architectures you want. Run `go tool dist list` for available architectures. 
 build linux amd64
+[[ "$1" = "linux64-only" ]] && exit 0
 build linux 386
 build linux arm
 build linux arm64
-- 
GitLab