forked from operately/operately
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevenv
More file actions
executable file
·81 lines (73 loc) · 2.66 KB
/
devenv
File metadata and controls
executable file
·81 lines (73 loc) · 2.66 KB
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
#!/usr/bin/env bash
#
# A wrapper around the docker command to make it easier to run commands in
# the app container accross Linux and MacOS. On MacOS, the user and group
# ids are different than on Linux, so we need to pass them in as environment
# variables to the container. This script will set the USER_ID and GROUP_ID
# environment variables to the current user and group ids.
#
# The USER_ID and GROUP_ID environment variables are used in the docker-compose.yml
# file to set the user and group ids in the app container that is the same as the
# current user and group ids on the host machine. This is done to avoid permission
# issues when creating files in the app container.
#
#
# Usage:
#
# devenv build - Build the app container
# devenv up - Start the app container
# devenv stop - Stop the app container
# devenv down - Stop and remove the app container
# devenv shell - Start a shell in the app container
# devenv <command> - Run a command in the running app container
#
case "$(uname -s)" in
Linux)
#
# On Linux, we want to pass in the user and group ids as environment variables
# to the container so that the user and group ids in the container are the same
# as the user and group ids on the host machine. This is done to avoid permission
# issues when creating files in the app container.
#
export GROUP_ID=$(id -g)
export USER_ID=$(id -u)
;;
Darwin)
#
# On MacOS, the user and group ids are different than on Linux and can't be
# passed in as environment variables. Instead, we'll set the USER_ID and GROUP_ID
# environment variables to 1000, which is the default user and group id in the
# app container.
#
# This will on MacOS because Docker Desktop for Mac uses a file sharing system
# that doesn't require the user and group ids to be the same in the container
# as on the host machine.
export GROUP_ID=1000
export USER_ID=1000
;;
*)
echo "Unsupported OS"
exit 1
;;
esac
FIRST_ARG=$1
if [ "$CI" = "true" ]; then
PROFILE="ci"
else
PROFILE="dev"
fi
if [ "$FIRST_ARG" = "shell" ]; then
docker compose exec app bash
elif [ "$FIRST_ARG" = "up" ]; then
docker compose --profile ${PROFILE} up -d --force-recreate
elif [ "$FIRST_ARG" = "stop" ]; then
docker compose --profile ${PROFILE} stop
elif [ "$FIRST_ARG" = "down" ]; then
docker compose --profile ${PROFILE} down
elif [ "$FIRST_ARG" = "restart" ]; then
docker compose --profile ${PROFILE} down && docker compose --profile ${PROFILE} up -d --force-recreate
elif [ "$FIRST_ARG" = "build" ]; then
docker compose build --no-cache
else
docker compose exec app "$@"
fi