-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsanic.yaml
More file actions
126 lines (124 loc) · 4.5 KB
/
sanic.yaml
File metadata and controls
126 lines (124 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
commands:
- name: build_protocol
command: |
set -eu -o pipefail
echo "Building protocol..."
if [ -z "$(which protoc)" ]; then
echo "You must install protoc: https://github.com/protocolbuffers/protobuf/releases"
cd /tmp
rm protoc-*.zip || true
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/protoc-3.10.1-linux-x86_64.zip
sudo bash -c '
rm -rf /opt/protobuf &&
mkdir /opt/protobuf &&
cd /opt/protobuf &&
unzip /tmp/protoc-3.10.1-linux-x86_64.zip &&
find /opt/protobuf/ -type d -exec chmod 755 {} \; &&
find /opt/protobuf/ -type f -exec chmod 644 {} \; &&
find /opt/protobuf/bin -type f -exec chmod 755 {} \;
'
echo 'export PATH="$PATH:/opt/protobuf/bin"' >> ~/.bashrc
echo 'You must type "source ~/.bashrc" and rerun "sanic run build_protocol" now.'
exit 1
fi
if [ -z "$(which protoc-gen-go)" ]; then
echo "Installing protoc-gen-go..."
unset GO111MODULE
go get -u github.com/golang/protobuf/protoc-gen-go
echo "Installed!"
fi
( cd src/protocol && protoc -I=. --go_out=. *.proto; )
- name: fix_imports
command: |
set -eu
echo "fixing imports for $1..."
libraries=($(ls -1 src | sort))
cd $1
sed -i '\~replace github.com/layer-devops/wrap.sh/src/~d' go.mod
replacements=()
for lib in "${libraries[@]}"; do
replacements+=("replace github.com/layer-devops/wrap.sh/src/$lib => ../$lib")
done
printf '%s\n' "${replacements[@]}" >> go.mod
go mod tidy -v
- name: go_mod_vendor
command: |
set -eu
echo "go mod vendor for $1..."
cd $1
go mod vendor
- name: cleanup
command: |
set -eu -o pipefail
echo "Cleaning up..."
sanic run build_protocol
echo "Fixing imports..."
find . -name 'go.mod' | grep -v vendor | xargs -I {} dirname {} | xargs -I {} -P 5 sanic run fix_imports {}
find . -name 'go.mod' | grep -v vendor | xargs -I {} dirname {} | xargs -I {} -P 5 sanic run go_mod_vendor {}
echo 'Running gofmt...'
find . -name '*.go' -not -path "*/vendor/*" -exec gofmt -s -w {} \;
echo 'Removing dockerfiles...'
# sanic will build random vendored dockerfiles unless we remove them
find . -name 'Dockerfile' -path "*/vendor/*" -delete
find . -name 'Dockerfile' -path "*/node_modules/*" -delete
- name: setup_dns
command: |
echo "Setting up dnsmasq..."
dnsmasq --version >/dev/null 2>&1 || {
sudo apt-get update
sudo apt-get -y install dnsmasq
}
sudo systemctl disable dnsmasq
sudo sed -i '/dns=dnsmasq/d' /etc/NetworkManager/NetworkManager.conf
sudo sed -i '/plugins=/a dns=dnsmasq' /etc/NetworkManager/NetworkManager.conf
sudo rm /etc/resolv.conf
sudo ln -s /var/run/NetworkManager/resolv.conf /etc/resolv.conf
cat <<EOF | sudo tee /etc/NetworkManager/dnsmasq.d/example.com-wildcard.conf
address=/.wraplocal.sh/127.0.0.1
address=/wraplocal.sh/127.0.0.1
EOF
sudo systemctl restart NetworkManager
- name: setup_for_development
command: |
set -eu -o pipefail
echo "Setting up for wrap.sh development..."
sanic run setup_dns
sanic run cleanup
echo "Setup complete!"
- name: gotest
command: |
set -eu -o pipefail
echo "Running gotest..."
find src -name '*_test.go' \
| grep -v vendor \
| xargs -I {} dirname {} | sort | uniq | xargs -I {} bash -c "cd {} && go test ."
environments:
dev:
commands:
- name: build
command: |
set -eu -o pipefail
sanic run cleanup
mkdir -p bin/dev
cd src/wrap
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
echo "Building..."
go build -mod=vendor -tags netgo -ldflags '-w -X main.localDevBuild=true -X main.debugLog=true' \
-o ../../bin/dev/wrap-linux-amd64
echo "Successfully built bin/dev/wrap-linux-amd64"
prod:
commands:
- name: build
command: |
set -eu -o pipefail
sanic run cleanup
mkdir -p bin/prod
cd src/wrap
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
echo "Building..."
go build -mod=vendor -tags netgo -ldflags '-w' -o ../../bin/prod/wrap-linux-amd64
echo "Successfully built bin/prod/wrap-linux-amd64"