Initial commit
This commit is contained in:
34
misc/docker/Dockerfile
Normal file
34
misc/docker/Dockerfile
Normal file
@ -0,0 +1,34 @@
|
||||
FROM golang:1.15 AS build
|
||||
|
||||
ARG HTTP_PROXY=
|
||||
ARG HTTPS_PROXY=
|
||||
ARG http_proxy=
|
||||
ARG https_proxy=
|
||||
|
||||
RUN apt-get update && apt-get install -y build-essential git bash curl
|
||||
|
||||
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
|
||||
&& apt-get install -y nodejs
|
||||
|
||||
COPY . /src
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
RUN cp -f misc/docker/config-patch.yml misc/release/config-patch.yml
|
||||
|
||||
RUN go get github.com/krishicks/yaml-patch/cmd/yaml-patch
|
||||
|
||||
RUN npm install \
|
||||
&& make vendor \
|
||||
&& echo "---" > ./misc/release/config-patch.yml \
|
||||
&& make ARCH_TARGETS=amd64 release
|
||||
|
||||
FROM busybox
|
||||
|
||||
COPY --from=build /src/release/fake-sms-linux-amd64 /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN mkdir -p /app
|
||||
|
||||
CMD ["bin/fake-sms", "--config", "config.yml"]
|
1
misc/docker/config-patch.yml
Normal file
1
misc/docker/config-patch.yml
Normal file
@ -0,0 +1 @@
|
||||
---
|
4
misc/release/config-patch.yml
Normal file
4
misc/release/config-patch.yml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
- op: replace
|
||||
path: /data/path
|
||||
value: /var/lib/fake-sms/data.db
|
124
misc/script/release.sh
Executable file
124
misc/script/release.sh
Executable file
@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
OS_TARGETS=( linux )
|
||||
ARCH_TARGETS=${ARCH_TARGETS:-amd64 arm 386}
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
PROJECT_DIR="$DIR/../.."
|
||||
|
||||
function build {
|
||||
|
||||
local name=$1
|
||||
local srcdir=$2
|
||||
local os=$3
|
||||
local arch=$4
|
||||
|
||||
local dirname="$name-$os-$arch"
|
||||
local destdir="$PROJECT_DIR/release/$dirname"
|
||||
|
||||
rm -rf "$destdir"
|
||||
mkdir -p "$destdir"
|
||||
|
||||
echo "building $dirname..."
|
||||
|
||||
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \
|
||||
-ldflags="-s -w -X 'main.GitRef=$(current_commit_ref)' -X 'main.ProjectVersion=$(current_version)' -X 'main.BuildDate=$(current_date)'" \
|
||||
-gcflags=-trimpath="${PWD}" \
|
||||
-asmflags=-trimpath="${PWD}" \
|
||||
-o "$destdir/bin/$name" \
|
||||
"$srcdir"
|
||||
|
||||
if [ ! -z "$(which upx)" ]; then
|
||||
upx --best "$destdir/bin/$name"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function current_date {
|
||||
date '+%Y-%m-%d %H:%M'
|
||||
}
|
||||
|
||||
function current_commit_ref {
|
||||
git log -n 1 --pretty="format:%h"
|
||||
}
|
||||
|
||||
function current_version {
|
||||
local latest_tag=$(git describe --abbrev=0 2>/dev/null)
|
||||
echo ${latest_tag:-0.0.0}
|
||||
}
|
||||
|
||||
function copy {
|
||||
|
||||
local name=$1
|
||||
local os=$2
|
||||
local arch=$3
|
||||
local src=$4
|
||||
local dest=$5
|
||||
|
||||
local dirname="$name-$os-$arch"
|
||||
local destdir="$PROJECT_DIR/release/$dirname"
|
||||
|
||||
echo "copying '$src' to '$destdir/$dest'..."
|
||||
|
||||
mkdir -p "$(dirname $destdir/$dest)"
|
||||
|
||||
cp -rfL $src "$destdir/$dest"
|
||||
|
||||
}
|
||||
|
||||
function dump_default_conf {
|
||||
# Generate and copy configuration file
|
||||
local command=$1
|
||||
local os=$2
|
||||
local arch=$3
|
||||
local tmp_conf=$(mktemp)
|
||||
local patched_conf=$(mktemp)
|
||||
|
||||
go run "$PROJECT_DIR/cmd/$command" -dump-config > "$tmp_conf"
|
||||
cat "$tmp_conf" | yaml-patch -o misc/release/config-patch.yml > "$patched_conf"
|
||||
copy "$command" $os $arch "$patched_conf" "config.yml"
|
||||
rm -f "$tmp_conf" "$patched_conf"
|
||||
}
|
||||
|
||||
function compress {
|
||||
|
||||
local name=$1
|
||||
local os=$2
|
||||
local arch=$3
|
||||
|
||||
local dirname="$name-$os-$arch"
|
||||
local destdir="$PROJECT_DIR/release/$dirname"
|
||||
|
||||
echo "compressing $dirname..."
|
||||
tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname"
|
||||
}
|
||||
|
||||
function release_fakesms {
|
||||
|
||||
local os=$1
|
||||
local arch=$2
|
||||
|
||||
build 'fake-sms' "$PROJECT_DIR/cmd/fake-sms" $os $arch
|
||||
|
||||
dump_default_conf 'fake-sms' $os $arch
|
||||
|
||||
copy 'fake-sms' $os $arch "$PROJECT_DIR/README.md" "README.md"
|
||||
copy 'fake-sms' $os $arch "$PROJECT_DIR/cmd/fake-sms/public/dist" "public"
|
||||
copy 'fake-sms' $os $arch "$PROJECT_DIR/cmd/fake-sms/template" "template"
|
||||
|
||||
compress 'fake-sms' $os $arch
|
||||
|
||||
}
|
||||
|
||||
function main {
|
||||
|
||||
for os in ${OS_TARGETS[@]}; do
|
||||
for arch in ${ARCH_TARGETS[@]}; do
|
||||
release_fakesms $os $arch
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
main
|
Reference in New Issue
Block a user