chore(project): bootstrap project tree
This commit is contained in:
18
misc/containers/hydra/Dockerfile
Normal file
18
misc/containers/hydra/Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
FROM oryd/hydra:v1.4.2-alpine
|
||||
|
||||
USER root
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||
RUN chmod a+x /usr/local/bin/docker-entrypoint
|
||||
|
||||
COPY first-run.sh /usr/local/bin/docker-first-run
|
||||
RUN chmod a+x /usr/local/bin/docker-first-run
|
||||
|
||||
COPY hydra-init.d /hydra-init.d
|
||||
|
||||
RUN mkdir -p /home/ory && chown -R ory: /home/ory
|
||||
USER ory
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
|
||||
|
||||
CMD ["hydra", "serve", "all"]
|
14
misc/containers/hydra/docker-entrypoint.sh
Normal file
14
misc/containers/hydra/docker-entrypoint.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -xeo pipefail
|
||||
|
||||
LIFECYCLEFLAGS_DIR="$HOME/.container-lifecycle"
|
||||
|
||||
mkdir -p "$LIFECYCLEFLAGS_DIR"
|
||||
|
||||
if [ ! -f "$LIFECYCLEFLAGS_DIR/first-run" ]; then
|
||||
/usr/local/bin/docker-first-run
|
||||
touch "$LIFECYCLEFLAGS_DIR/first-run"
|
||||
fi
|
||||
|
||||
exec "$@"
|
8
misc/containers/hydra/first-run.sh
Normal file
8
misc/containers/hydra/first-run.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
hydra migrate sql -e -y
|
||||
|
||||
hydra serve all --dangerous-force-http &
|
||||
HYDRA_PID=$!
|
||||
run-parts --exit-on-error /hydra-init.d
|
||||
kill $HYDRA_PID
|
12
misc/containers/hydra/hydra-init.d/create-client
Executable file
12
misc/containers/hydra/hydra-init.d/create-client
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
|
||||
hydra clients create \
|
||||
--id guesstimate \
|
||||
--secret guesstimate \
|
||||
-n Guesstimate \
|
||||
-a email,email_verified,openid \
|
||||
--token-endpoint-auth-method client_secret_post \
|
||||
--post-logout-callbacks http://localhost:8081/logout/redirect \
|
||||
-c http://localhost:8081/oauth2/callback
|
3
misc/containers/postgres/Dockerfile
Normal file
3
misc/containers/postgres/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM postgres:12-alpine
|
||||
|
||||
COPY ./initdb.d /docker-entrypoint-initdb.d
|
16
misc/containers/postgres/initdb.d/init-databases.sh
Normal file
16
misc/containers/postgres/initdb.d/init-databases.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||
CREATE USER hydra WITH ENCRYPTED PASSWORD 'hydra';
|
||||
CREATE DATABASE hydra;
|
||||
GRANT ALL PRIVILEGES ON DATABASE hydra TO hydra;
|
||||
EOSQL
|
||||
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||
CREATE USER guesstimate WITH ENCRYPTED PASSWORD 'guesstimate';
|
||||
CREATE DATABASE guesstimate;
|
||||
GRANT ALL PRIVILEGES ON DATABASE guesstimate TO guesstimate;
|
||||
ALTER DATABASE guesstimate OWNER TO guesstimate;
|
||||
EOSQL
|
119
misc/script/release
Executable file
119
misc/script/release
Executable file
@ -0,0 +1,119 @@
|
||||
#!/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.GitCommit=$(current_commit_ref) -X main.ProjectVersion=$(current_version)" \
|
||||
-gcflags=-trimpath="${PWD}" \
|
||||
-asmflags=-trimpath="${PWD}" \
|
||||
-o "$destdir/bin/$name" \
|
||||
"$srcdir"
|
||||
|
||||
if [ ! -z "$(which upx)" ]; then
|
||||
upx --best "$destdir/bin/$name"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function current_commit_ref {
|
||||
git rev-list -1 HEAD
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
go run "$PROJECT_DIR/cmd/$command" -dump-config > "$tmp_conf"
|
||||
copy "$command" $os $arch "$tmp_conf" "$command.conf"
|
||||
rm -f "$tmp_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_server {
|
||||
|
||||
local os=$1
|
||||
local arch=$2
|
||||
|
||||
build 'server' "$PROJECT_DIR/cmd/server" $os $arch
|
||||
|
||||
dump_default_conf 'server' $os $arch
|
||||
|
||||
copy 'server' $os $arch "$PROJECT_DIR/README.md" "README.md"
|
||||
copy 'server' $os $arch "$PROJECT_DIR/client/dist" "public"
|
||||
|
||||
compress 'server' $os $arch
|
||||
|
||||
}
|
||||
|
||||
function main {
|
||||
|
||||
make client-dist
|
||||
|
||||
for os in ${OS_TARGETS[@]}; do
|
||||
for arch in ${ARCH_TARGETS[@]}; do
|
||||
release_server $os $arch
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
main
|
Reference in New Issue
Block a user