-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks
executable file
·149 lines (123 loc) · 3.45 KB
/
tasks
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
set -euo pipefail
COMPOSE_PROJECT_NAME=home-server-development
APP_SERVICE_NAME=app
APP_HEALTHCHECK_URL=http://0.0.0.0:5000
# Set container user ID
export FIXUID="$(id -u)"
export FIXGID="$(id -g)"
function build {
source ./config/env/build_args.env
docker compose \
-p $COMPOSE_PROJECT_NAME \
-f ./.docker/docker-compose/dev.yml \
build "$@"
}
function start {
docker compose \
-p $COMPOSE_PROJECT_NAME \
-f ./.docker/docker-compose/dev.yml \
up "$@"
}
function stop {
docker compose \
-p $COMPOSE_PROJECT_NAME \
-f ./.docker/docker-compose/dev.yml \
down "$@"
}
function run {
docker compose \
-p $COMPOSE_PROJECT_NAME \
-f ./.docker/docker-compose/dev.yml \
run $APP_SERVICE_NAME /bin/bash -c "source ./.docker/scripts/entrypoint-dev && $*"
}
function exec {
ensure_app_container_running
docker compose \
-p $COMPOSE_PROJECT_NAME \
-f ./.docker/docker-compose/dev.yml \
exec $APP_SERVICE_NAME /bin/bash -c "source ./.docker/scripts/entrypoint-dev && $*"
}
function sh {
ensure_app_container_running
docker compose \
-p $COMPOSE_PROJECT_NAME \
-f ./.docker/docker-compose/dev.yml \
exec $APP_SERVICE_NAME /bin/bash --init-file ./.docker/scripts/entrypoint-dev
}
function rails {
exec bundle exec rails "$@"
}
function yarn {
exec yarn "$@"
}
function bundle {
exec bundle "$@"
}
function rubocop {
exec bundle exec rubocop "$@"
}
function attach {
docker attach --detach-keys="ctrl-c" home-server-app-dev
}
function rspec {
ensure_app_container_running
docker compose \
-p $COMPOSE_PROJECT_NAME \
-f ./.docker/docker-compose/dev.yml \
exec -e RAILS_ENV=test $APP_SERVICE_NAME \
/bin/bash -c "source ./.docker/scripts/entrypoint-dev && bundle exec rspec $*"
}
function ensure_app_container_running {
(! (docker ps | grep -q $COMPOSE_PROJECT_NAME)) && up -d
until curl --output /dev/null --silent --head "$APP_HEALTHCHECK_URL" ; do
echo 'waiting for app...'
sleep 2.5
done
}
function build-all-images {
build-images-base
build-images-app
build-images-worker
build
}
function build-images-base {
source ./config/env/build_args.env
[ -z "$GRECAPTCHA_SITE_KEY" ] && echo "GRECAPTCHA_SITE_KEY empty, set in config/env/build_args.env" && exit 1
[ -z "$MAX_MIND_LICENSE" ] && echo "MAX_MIND_LICENSE empty, set in config/env/build_args.env" && exit 1
GIT_SHA="$(git rev-parse HEAD | head -c8)"
docker build \
--build-arg MAX_MIND_LICENSE="$MAX_MIND_LICENSE" \
--build-arg grecaptcha_site_key="$GRECAPTCHA_SITE_KEY" \
-t cpcwood/home-server-base:latest \
-t cpcwood/home-server-base:"$GIT_SHA" \
-f ./.docker/dockerfiles/base.Dockerfile \
.
}
function build-images-app {
GIT_SHA="$(git rev-parse HEAD | head -c8)"
docker build \
-t cpcwood/home-server-app:latest \
-t cpcwood/home-server-app:"$GIT_SHA" \
-f ./.docker/dockerfiles/Dockerfile \
.
}
function build-images-worker {
GIT_SHA="$(git rev-parse HEAD | head -c8)"
docker build \
-t cpcwood/home-server-worker-dependencies:latest \
-t cpcwood/home-server-worker-dependencies:"$GIT_SHA" \
-f ./.docker/dockerfiles/worker-dependencies.Dockerfile \
.
docker build \
-t cpcwood/home-server-worker:latest \
-t cpcwood/home-server-worker:"$GIT_SHA" \
-f ./.docker/dockerfiles/worker.Dockerfile \
.
}
if [[ ! $(type -t "$1") == function ]]; then
echo "Invalid command entered"
exit 1
fi
TIMEFORMAT="Task completed in %3lR"
time "${@:-default}"