forked from theia-ide/theia-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_container.sh
executable file
·42 lines (33 loc) · 1.59 KB
/
build_container.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
#!/bin/bash
set -e
# this script is called by GH workflows to build the Docker image
NPM_TAG=$1
IMAGE_NAME=$2
NODE_VERSION=$3
GH_TOKEN=$4
# Theia standard port is listening in port 3000 (the common nodejs port), and it is exposed when running the docker
# container (-p 0.0.0.0:4000:3000). But some new applications may need to change it (e.g. theia-https-docker).
# This 5th parameter enables to expose a custom port instead of the common 3000 port. It is set to 3000 as a default
# value if not included, for backward compatibility.
PORT=${5:-3000}
shift
shift
shift
shift
# We know that there are at least 4 parameters. If we shift the 5th parameter and it is not set, shift will fail thus
# failing the script (because of set -e)
[ $# -gt 0 ] && shift
cd "$IMAGE_NAME-docker"
IMAGE="theiaide/$IMAGE_NAME"
IMAGE_TAG="$IMAGE:$NPM_TAG"
docker build --build-arg "version=$NPM_TAG" --build-arg "NODE_VERSION=$NODE_VERSION" --build-arg "GITHUB_TOKEN=$GH_TOKEN" . -t "$IMAGE_TAG" --no-cache
# Tag the image with the solid version if it is `latest`.
# Then, we have 2 tags refer to the same image, i.e: "theiaide/theia:1.12.1" and "theiaide/theia:latest".
if [ $NPM_TAG = "latest" ]; then
IMAGE_SOLID_TAG="$IMAGE":$(npm view "@theia/core@$NPM_TAG" version)
docker tag "$IMAGE_TAG" "$IMAGE_SOLID_TAG"
fi
docker images "$IMAGE"
# Now we allow to pass extra parameters to the docker run command: any extra parameter to build_container.sh is
# interpreted as a parameter to docker run (it is useful for e.g. passing environment variables or volume mappings)
docker run --init -d "$@" -p 0.0.0.0:4000:$PORT "$IMAGE_TAG"