@toptal/davinci-ci 7.3.1 → 7.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +14 -0
- package/README.md +2 -0
- package/package.json +2 -2
- package/src/configs/docker/Dockerfile.gha-deploy +4 -0
- package/src/configs/docker/env-runtime.entrypoint.sh +5 -1
- package/src/configs/docker/import-davinci-environment-file.sh +31 -0
- package/src/configs/docker/import-davinci-environment-file.test.sh +56 -0
- package/src/configs/docker/nginx-vhost.conf +5 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 7.4.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- [#2368](https://github.com/toptal/davinci/pull/2368) [`676ef4fd`](https://github.com/toptal/davinci/commit/676ef4fdc68cee6766903fb811274c470bf3a5ee) Thanks [@sashuk](https://github.com/sashuk)!
|
8
|
+
- add ability to override environment variables by reading environment files
|
9
|
+
|
10
|
+
## 7.3.2
|
11
|
+
|
12
|
+
### Patch Changes
|
13
|
+
|
14
|
+
- [#2376](https://github.com/toptal/davinci/pull/2376) [`edcf6971`](https://github.com/toptal/davinci/commit/edcf6971a1b97af0f38424e3174dad75e50f5aed) Thanks [@augustobmoura](https://github.com/augustobmoura)!
|
15
|
+
- bump new version of davinci-cli-shared on all projects
|
16
|
+
|
3
17
|
## 7.3.1
|
4
18
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
@@ -85,6 +85,8 @@ The image is present on path `src/configs/docker/Dockerfile.gha-deploy` and have
|
|
85
85
|
| `NGINX_CONFIG` | Ngninx config, davinci has an example file present at `src/configs/docker/nginx-vhost.conf` | Yes |
|
86
86
|
| `HTML_CDN_CACHE_TAG` | `Cache-Tag` header for HTML documents, used for specific cache purging | No |
|
87
87
|
|
88
|
+
The default entrypoint `src/configs/docker/env-runtime.entrypoint.sh` reads environment file (`.env.$DAVINCI_ENV` has to be located in the root of the dist folder) and populates the environment variables with values from the file if the overriden environment variable is not set. Variables that are provided to `docker run` command (for example, `docker run -e DAVINCI_envvar1=1`) have higher priority that variables from the envrionment file.
|
89
|
+
|
88
90
|
### IDE Tooling
|
89
91
|
|
90
92
|
This package can be used directly in your IDE through these extensions
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@toptal/davinci-ci",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.4.0",
|
4
4
|
"keywords": [
|
5
5
|
"ci",
|
6
6
|
"docker",
|
@@ -30,7 +30,7 @@
|
|
30
30
|
"dependencies": {
|
31
31
|
"@commitlint/cli": "^17.6.7",
|
32
32
|
"@commitlint/config-conventional": "^17.1.0",
|
33
|
-
"@toptal/davinci-cli-shared": "^2.
|
33
|
+
"@toptal/davinci-cli-shared": "^2.4.0",
|
34
34
|
"chalk": "^4.1.2",
|
35
35
|
"danger": "^11.2.2",
|
36
36
|
"markdown-table": "^2.0.0"
|
@@ -15,6 +15,10 @@ RUN [ -z "$ENV_RUNTIME_ENTRYPOINT" ] && echo "ENV_RUNTIME_ENTRYPOINT is required
|
|
15
15
|
COPY $ENV_RUNTIME_ENTRYPOINT /usr/local/bin/env-runtime.entrypoint.sh
|
16
16
|
RUN chmod +x /usr/local/bin/env-runtime.entrypoint.sh
|
17
17
|
|
18
|
+
# Copy script that reads .env file and replaces DAVINCI_* environment variables if they are empty
|
19
|
+
COPY ./davinci/packages/ci/src/configs/docker/import-davinci-environment-file.sh /usr/local/bin/import-davinci-environment-file.sh
|
20
|
+
RUN chmod +x /usr/local/bin/import-davinci-environment-file.sh
|
21
|
+
|
18
22
|
# version is used in build process, so the value won't be available here otherwise
|
19
23
|
ARG VERSION
|
20
24
|
RUN [ -z "$VERSION" ] && echo "VERSION is required" && exit 1 || true
|
@@ -13,7 +13,11 @@
|
|
13
13
|
|
14
14
|
# keep in sync with index.html
|
15
15
|
VARS_PREFIX="DAVINCI_"
|
16
|
-
|
16
|
+
DIST_PATH="/usr/share/nginx/html"
|
17
|
+
INDEX_FILE="$DIST_PATH/index.html"
|
18
|
+
|
19
|
+
# import environment variables from .env.DAVINCI_ENV file depending
|
20
|
+
source import-davinci-environment-file.sh
|
17
21
|
|
18
22
|
VARS="$(env | grep $VARS_PREFIX | awk -F = '{print $1}')"
|
19
23
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/bin/sh -e
|
2
|
+
|
3
|
+
# Reads environment variables from .env.$DAVINCI_ENV file and overrides every empty
|
4
|
+
# variable in the existing environment
|
5
|
+
# See import-davinci-environment-file.test.sh for testing
|
6
|
+
|
7
|
+
if [ -z "$DAVINCI_ENV" ]; then
|
8
|
+
echo "Error: DAVINCI_ENV is empty"
|
9
|
+
exit 1
|
10
|
+
fi
|
11
|
+
|
12
|
+
if [ -z "$DIST_PATH" ]; then
|
13
|
+
echo "Error: DIST_PATH is empty"
|
14
|
+
exit 1
|
15
|
+
fi
|
16
|
+
|
17
|
+
ENV_FILE="$DIST_PATH/.env.$DAVINCI_ENV"
|
18
|
+
if [ -f "$ENV_FILE" ]; then
|
19
|
+
echo "Info: $ENV_FILE exists, importing variables..."
|
20
|
+
|
21
|
+
# Store current environment variables
|
22
|
+
OLD_ENV="$(export -p)"
|
23
|
+
|
24
|
+
# Load env file variables
|
25
|
+
export $(grep -v '^#' $ENV_FILE | xargs)
|
26
|
+
|
27
|
+
# Override env variables with previous values
|
28
|
+
eval "$OLD_ENV"
|
29
|
+
else
|
30
|
+
echo "Info: $ENV_FILE does not exist"
|
31
|
+
fi
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# How to run test:
|
4
|
+
# - navigate to this folder in bash
|
5
|
+
# - run script "./import-davinci-environment-variables.test.sh", there should be no lines with "Assertion failed"
|
6
|
+
|
7
|
+
# Set up test environment
|
8
|
+
export TMP_PATH="./tmp"
|
9
|
+
mkdir -p "$TMP_PATH"
|
10
|
+
export DIST_PATH="$TMP_PATH"
|
11
|
+
|
12
|
+
# Set up console colors
|
13
|
+
RED='\033[0;31m'
|
14
|
+
NC='\033[0m'
|
15
|
+
|
16
|
+
############
|
17
|
+
# Test case:
|
18
|
+
# - EMPTY_VARIALBE_ABC value is replaced with value from .env.staging if the value in .env.staging is not empty
|
19
|
+
# - EMPTY_VARIALBE_DEF value stays empty as the value in .env.staging is empty
|
20
|
+
# - NON_EMPTY_VARIABLE value is not replaced with value from .env.staging
|
21
|
+
############
|
22
|
+
|
23
|
+
export DAVINCI_ENV="staging"
|
24
|
+
export NON_EMPTY_VARIABLE="123"
|
25
|
+
printf "%s\n" "EMPTY_VARIALBE_ABC=from-env-file" "EMPTY_VARIALBE_DEF=" "NON_EMPTY_VARIABLE=from-env-file" "RANDOM_VARIABLE=456" > "$DIST_PATH/.env.$DAVINCI_ENV"
|
26
|
+
|
27
|
+
set -a
|
28
|
+
source import-davinci-environment-file.sh
|
29
|
+
|
30
|
+
if [ "$EMPTY_VARIALBE_ABC" != "from-env-file" ]; then
|
31
|
+
echo -e "${RED}Assertion failed:${NC} EMPTY_VARIALBE_ABC is not equal to expected_value (received \"$EMPTY_VARIALBE_ABC\")"
|
32
|
+
exit 1
|
33
|
+
fi
|
34
|
+
|
35
|
+
if [ "$EMPTY_VARIALBE_DEF" != "" ]; then
|
36
|
+
echo -e "${RED}Assertion failed:${NC} EMPTY_VARIALBE_DEF is not equal to expected_value (received \"$EMPTY_VARIALBE_DEF\")"
|
37
|
+
exit 1
|
38
|
+
fi
|
39
|
+
|
40
|
+
if [ "$NON_EMPTY_VARIABLE" != "123" ]; then
|
41
|
+
echo -e "${RED}Assertion failed:${NC} NON_EMPTY_VARIABLE is not equal to expected_value"
|
42
|
+
exit 1
|
43
|
+
fi
|
44
|
+
|
45
|
+
# Clean up test environment
|
46
|
+
rm -rf "$TMP_PATH"
|
47
|
+
|
48
|
+
###########
|
49
|
+
# Test case: environment file does not exist
|
50
|
+
###########
|
51
|
+
command_output=$(source import-davinci-environment-file.sh)
|
52
|
+
|
53
|
+
if [ "$command_output" != "Info: $DIST_PATH/.env.$DAVINCI_ENV does not exist" ]; then
|
54
|
+
echo -e "${RED}Assertion failed:${NC} command_output is not equal to expected_value (received \"$command_output\")"
|
55
|
+
exit 1
|
56
|
+
fi
|