Skip to content

Commit ffd89d4

Browse files
committed
build: switch to fully dockerized build
1 parent b6aa69c commit ffd89d4

File tree

5 files changed

+92
-62
lines changed

5 files changed

+92
-62
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# node:18-bullseye @ 2022-07-10T19:41:00
2+
DOCKER_NODE_VERSION=@sha256:9029bbd08c882b874961793299a36276cc65f97012161c959e99e80a90055ca0

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.7'
22

33
services:
44
node:
5-
image: node:${NODE_VERSION}
5+
image: node${DOCKER_NODE_VERSION}
66
restart: 'never'
77
ports:
88
- '3000:3000'

git-conventional-commits.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build",
1111
"ops",
1212
"docs",
13-
"chore",
13+
"security",
1414
"merge",
1515
"revert"
1616
],
@@ -33,6 +33,7 @@
3333
"fix": "Bug Fixes",
3434
"perf": "Performance Improvements",
3535
"merge": "Merged Branches",
36+
"security": "Security",
3637
"breakingChange": "BREAKING CHANGES"
3738
},
3839

source.sh

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
#!/bin/bash
22

3-
export NODE_VERSION="16.6.2"
4-
export DOCKER_PWD="$(pwd)"
3+
source .env
4+
5+
export COMPOSE_PROJECT_NAME=vue-step-progress
6+
7+
export DOCKER_PWD=$(pwd)
58
export DOCKER_USER="$(id -u):$(id -g)"
9+
10+
function _docker_cmd() {
11+
local ti_arg="-t"
12+
13+
# if tty is available also open input
14+
if [ -t 1 ] ; then
15+
ti_arg="${ti_arg}i"
16+
fi
17+
18+
docker run "$ti_arg" --rm -u "$DOCKER_USER" -v "$(pwd)":"$(pwd)" -w "$(pwd)" "$@"
19+
}
20+
21+
function _npm() {
22+
_docker_cmd "node${DOCKER_NODE_VERSION}" npm "$@"
23+
}
24+
25+
function _node() {
26+
_docker_cmd "node${DOCKER_NODE_VERSION}" node "$@"
27+
}
28+
29+
function _node_run() {
30+
_docker_cmd "node${DOCKER_NODE_VERSION}" "$@"
31+
}
32+
33+
# if is interactive shell, define aliases
34+
if [[ $- == *i* ]] ; then
35+
alias npm="_npm"
36+
alias node="_node"
37+
fi

start.sh

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,13 @@ set -euo pipefail
33

44
source ./source.sh
55

6-
#doc> _docIndent_
7-
#doc>> Indents and filters the documentation depeding on the number of
8-
#doc>> '>' characters used.
9-
function docIndent() {
10-
DOCTYPE=${1-'[a-zA-Z0-9]*'}
11-
12-
script=$(cat <<'EOD'
13-
my $dt = $ENV{DOCTYPE};
14-
while(<>) {
15-
if($_ =~ /^#$dt(>+)/) {
16-
$_ =~ s/^#$dt//;
17-
$_ =~ s/^( *)>\s*/$1 / while($_ =~ /^ *>\s*/);
18-
print $_;
19-
}
20-
}
21-
EOD
22-
)
23-
24-
DOCTYPE="$DOCTYPE" perl -e "$script"
25-
}
26-
27-
#doc> _docPretty_
28-
#doc>> Use simple markup to underline headlines.
29-
function docPretty() {
30-
perl -pne 's/^( *)_(.+)_/\n$1'"$(tput smul)"'$2'"$(tput rmul)"'/'
31-
}
32-
33-
#> _help_
34-
#>> Print an overview of all targets.
35-
function help() {
36-
echo "usage: $0 COMMAND"
37-
echo ""
38-
echo "Commands:"
39-
docIndent "" < "$0" | docPretty
40-
}
41-
42-
#> _dev_
43-
#>> Start the development node server
446
function dev() {
457
if [ ! -d node_modules ] ; then
46-
npm install
47-
fi
48-
npm run dev
49-
}
50-
51-
#> _dev-container_ [COMMAND...]
52-
#>> Start the development container with the given command. If no
53-
#>> command is given, the development server is started instead.
54-
function dev_container() {
55-
local ARGS=("$@")
56-
if ! ((${#ARGS[@]})); then
57-
ARGS=("./start.sh" "dev")
8+
_npm install
589
fi
59-
docker-compose -f docker-compose.dev.yml run --service-ports --rm node ${ARGS[*]}
10+
docker-compose -f docker-compose.dev.yml run --service-ports --rm node npm run dev
6011
}
6112

62-
#> _build_
63-
#>> Do a production-ready build
6413
function build() {
6514
if [ "$(id -u)" == "0" ] ; then
6615
echo 'warning: trying to build as root user, falling back to user 1000'
@@ -75,20 +24,66 @@ function build() {
7524
}
7625

7726
case "${1-}" in
78-
"help" )
79-
help;;
8027
"dev" )
8128
dev;;
82-
"dev-container" )
83-
dev_container "${@:2}" ;;
8429
"build" )
8530
build;;
31+
"release" )
32+
if [[ -f .npmrc ]] ; then
33+
echo "no .npmrc file exists, please create it (//registry.npmjs.org/:_authToken=<token>)"
34+
exit 1
35+
fi
36+
37+
if ! _npm whoami ; then
38+
echo "you need to be logged into the npm registry before creating a release"
39+
exit 1
40+
fi
41+
42+
VERSION=$(git-conventional-commits version)
43+
echo "-- creating release for version ${VERSION}"
44+
45+
echo "-- patching package{,-lock}.json"
46+
jq ".version=\"${VERSION}\"" package.json > package.json.tmp && mv package.json.tmp package.json
47+
_npm i >/dev/null
48+
49+
echo "-- building release artifacts"
50+
build
51+
52+
echo "-- creating release commit"
53+
git commit -am"build(release): bump project version to ${VERSION}"
54+
55+
echo "-- creating changelog"
56+
git-conventional-commits changelog --release "$VERSION" --file CHANGELOG.md
57+
58+
echo "-- creating commit for changelog"
59+
git commit -am"doc(release): create ${VERSION} change log entry"
60+
61+
echo "-- tagging version"
62+
git tag -a -m"build(release): ${VERSION}" "v${VERSION}"
63+
64+
echo "-- tagging docker image"
65+
docker tag "${DOCKER_IMAGE_NAME}:latest" "${DOCKER_IMAGE_NAME}:${VERSION}"
66+
67+
read -r -p "-- git push? [Y/n]" response
68+
response=${response,,} # tolower
69+
if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
70+
git push --atomic origin master "v${VERSION}"
71+
fi
72+
73+
read -r -p "-- npm publish? [Y/n]" response
74+
response=${response,,} # tolower
75+
if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
76+
_npm publish
77+
fi
78+
79+
echo "-- RELEASE DONE"
80+
;;
81+
8682
*)
8783
if [ -z ${1+x} ]; then
8884
echo "no command given"
8985
else
9086
echo "invalid command '${1-}'"
9187
fi
92-
help
9388
exit 1;;
9489
esac

0 commit comments

Comments
 (0)