forked from 4km3/hms-containerbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint
executable file
·51 lines (40 loc) · 1.6 KB
/
entrypoint
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
#!/usr/bin/env bash
: "${GITHUB_REPO?Need a repository name}"
: "${GITHUB_BRANCH:=master}"
: "${GITHUB_USER?Need a GitHub username}"
: "${REPO_DIR:=.}"
: "${DOCKERHUB_USER?Need a DockerHub user}"
: "${DOCKERHUB_PASS?Need a DockerHub pass}"
: "${MAVEN_ACCEPTANCE_TEST_TARGET:=test}"
set -xe
# Clone repo and get inside
git clone \
-b "$GITHUB_BRANCH" \
https://github.com/"$GITHUB_USER"/"$GITHUB_REPO".git \
/srv/"$GITHUB_REPO"
cd /srv/"$GITHUB_REPO"/"$REPO_DIR"
# Extract artifact name and version from pom.xml
VERSION=$(xpath -q -e '/project/version/text()' pom.xml)
TARGET=$(xpath -q -e '/project/artifactId/text()' pom.xml)
# obtain $version artifact
cd /srv/"$GITHUB_REPO"/
wget https://github.com/$GITHUB_USER/$GITHUB_REPO/releases/download/$VERSION/$TARGET-linux-amd64
# Run the java jar with the included jre java
echo '127.0.0.1 ari' >> /etc/hosts
java -jar $TARGET-linux-amd64 "$@" &
echo $! > /run/$TARGET-$VERSION.pid
# Perform maven acceptance tests
cd /srv/"$GITHUB_REPO"/"$REPO_DIR"/acceptance-test
mvn $MAVEN_ACCEPTANCE_TEST_TARGET
kill -9 $(</run/$TARGET-$VERSION.pid)
# Prepare rancher-compose.yml
cd /srv/"$GITHUB_REPO"/
sed -i \
-e "s!@TARGET@!$TARGET!" \
Dockerfile
# Build dockerfile defined inside
cd /srv/"$GITHUB_REPO"/
docker build -t $DOCKERHUB_USER/$TARGET:$VERSION .
# Login to DockerHub and upload the container
docker login -u $DOCKERHUB_USER -p $DOCKERHUB_PASS
docker push $DOCKERHUB_USER/$TARGET:$VERSION