forked from fsouza/fake-gcs-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·72 lines (58 loc) · 2.2 KB
/
entrypoint.sh
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
#!/bin/bash -e
args=(
-backend "${INPUT_BACKEND}"
-cert-location "$(printenv INPUT_CERT-LOCATION)"
-private-key-location "$(printenv INPUT_PRIVATE-KEY-LOCATION)"
-port "${INPUT_PORT}"
-scheme "${INPUT_SCHEME}"
)
docker_args=(
--detach
--publish "${INPUT_PORT}":"${INPUT_PORT}"
)
INPUT_EXTERNAL_URL=$(printenv INPUT_EXTERNAL-URL)
INPUT_PUBLIC_HOST=$(printenv INPUT_PUBLIC-HOST)
docker_image=fsouza/fake-gcs-server:${INPUT_VERSION}
if [ -n "${INPUT_DATA}" ]; then
if [ -n "${INPUT_DEBUG}" ]; then
echo "INPUT_DATA=${INPUT_DATA}"
echo "RUNNER_WORKSPACE=${RUNNER_WORKSPACE}"
echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}"
echo "HOME=${HOME}"
fi
# RUNNER_WORKSPACE won't be populated at this point, so check the directory
# relative to GITHUB_WORKSPACE.
if ! [ -d "${GITHUB_WORKSPACE}/${INPUT_DATA}" ]; then
echo "ERROR: input data should be a directory. Make sure it exists and is specified as a relative path" >&2
exit 2
fi
# Github doesn't give us the repository name directly, so figure it out on
# our own.
REPOSITORY_NAME="${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}"/}"
# Build a data path relative to RUNNER_WORKSPACE, including the repository
# name that wasn't included in GITHUB_WORKSPACE.
DATA_PATH="${RUNNER_WORKSPACE}/${REPOSITORY_NAME}/${INPUT_DATA}"
args+=(-data "${DATA_PATH}")
docker_args+=(--volume "${DATA_PATH}:${DATA_PATH}")
fi
if [ -n "${INPUT_EXTERNAL_URL}" ]; then
args+=(-external-url "${INPUT_EXTERNAL_URL}")
fi
if [ -n "${INPUT_PUBLIC_HOST}" ]; then
args+=(-public-host "${INPUT_PUBLIC_HOST}")
fi
docker pull "${docker_image}"
container_id=$(docker run "${docker_args[@]}" "${docker_image}" "${args[@]}")
timeout=10
echo "waiting up to ${timeout}s for server to come up"
if ! timeout 10 bash -c 'while ! docker exec '"${container_id}"' wget -qO /dev/null -T 1 --no-check-certificate '"${INPUT_SCHEME}"'://0.0.0.0:'"${INPUT_PORT}"'/storage/v1/b; do echo "server not available yet, sleeping..."; sleep 1; done'; then
echo "Failed to connect to the server after ${timeout}s" >&2
echo "Logs from docker: " >&2
docker logs "${container_id}"
exit 1
fi
echo "Server started successfully!"
if [ -n "${INPUT_DEBUG}" ]; then
echo "Logs from container: "
docker logs "${container_id}"
fi