Skip to content

Commit

Permalink
chore(build): add top build.sh, refine build steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwq committed Jul 10, 2024
1 parent 3fdea4a commit 39ab564
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
50 changes: 50 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

#
# Terminate the test if any command below does not complete successfully.
set -e

# prepare for ldflags
_module_name=$(head go.mod | grep '^module' | awk '{print $2}')
_go_version=$(go version | grep 'version' | awk '{print $3}')
_git_tag=$(git describe --tags)
_git_commit=$(git rev-parse --short HEAD)
_git_branch=$(git rev-parse --abbrev-ref HEAD)

# prepre build tags
_osType=$(uname)
if [ "${_osType}" == 'Darwin' ]; then
_musl=$(otool -L /bin/ls | grep 'musl' | head -n 1 | awk '{print $1}')
else
_musl=$(ldd /bin/ls | grep 'musl' | head -n 1 | awk '{print $1}')
fi

if [ "$_musl" == "" ]; then
_build_tag="-tags utmp"
else
_build_tag="-tags utmps"
fi
echo "build with tags : $_build_tag"

# set ldflags
ldflags="-s -w \
-X $_module_name/frontend.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%S) \
-X $_module_name/frontend.GitBranch=$_git_branch \
-X $_module_name/frontend.GitCommit=$_git_commit \
-X $_module_name/frontend.GitTag=$_git_tag \
-X $_module_name/frontend.GoVersion=$_go_version \
"
# required for github.com/docker/docker
export GO111MODULE=auto

_dst="$HOME/.local/bin"
# build server and client
go build $_build_tag -ldflags="$ldflags" -o $_dst/apshd ./frontend/server
echo "build apshd to : $_dst"
go build -ldflags="$ldflags" -o $_dst/apsh ./frontend/client
echo "build apsh to : $_dst"

# run test
echo "run test :"
APRILSH_APSHD_PATH="$_dst/apshd" \
go test $_build_tag $(go list ./... | grep -Ev '(data|protobufs)')
17 changes: 7 additions & 10 deletions doc/install-alpine.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@

### add dependencies

build dependency.
```sh
apk add go protoc utmps-dev ncurses musl-locales ncurses-terminfo protoc-gen-go
```

run dependency.
```sh
apk add musl-locales utmps ncurses logrotate ncurses-terminfo openssh-server

```
### build from source
```sh
git clone https://github.com/ericwq/aprilsh.git
cd aprilsh/frontend/server
./build.sh
cd aprilsh/frontend/client
./build.sh
cd aprilsh
APRILSH_APSHD_PATH="/home/ide/.local/bin/apshd" \
go test -tags=utmps $(go list ./... | grep -Ev '(data|protobufs)')
./build.sh # build client and server, then run the test, only works on linux

# or you can build them separately.
cd frontend/server
./build.sh # build server, only works on linux
cd frontend/client
./build.sh # build client, works on linux and macOS
```
### install for alpine

Expand All @@ -30,7 +27,7 @@ add testing repositories to your alpine system, you need the root privilege to d
echo "https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
apk update
```
test souce code:
test source code:
```sh
APRILSH_APSHD_PATH="/home/ide/.local/bin/apshd" \
go test -tags=utmps $(go list ./... | grep -Ev '(data|protobufs)')
Expand Down

0 comments on commit 39ab564

Please sign in to comment.