Skip to content

Commit ac8e36e

Browse files
authored
Adding heroku.yml (#140)
1 parent 8bb6c3a commit ac8e36e

File tree

19 files changed

+390
-42
lines changed

19 files changed

+390
-42
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# Maven & Java
44
target/
5+
.classpath
6+
.project
7+
.settings/
58

69
# Node JS
710
build/

Dockerfile.heroku

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# For Heroku, we need to retrieve a "sh" shell from the "-debug" distroless version:
2+
FROM gcr.io/distroless/java:8-debug AS debug
3+
FROM vboard/vboard-front AS front
4+
FROM vboard/vboard-ws
5+
6+
COPY --from=debug /busybox/sh /bin
7+
# sed is required by setup_statics.sh:
8+
COPY --from=debug /busybox/sed /bin
9+
COPY --from=debug /busybox/ls /bin
10+
11+
# Spring Boot apps will automagically serve content from this directory:
12+
COPY --from=front /var/www/vboard /app/static
13+
# This copy could be avoided on next release of vboard-front, when it will contain setup_statics.sh:
14+
COPY vboard-front/setup_statics.sh /app/static
15+
16+
COPY bin/heroku_start.sh /app
17+
COPY bin/heroku_db_cleanup.sh /app
18+
19+
# Removing custom entrypoint:
20+
ENTRYPOINT []

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ V.Board is designed to be used for communication among an organization teams: pr
1515
This software has been used at oui.sncf since July 2016.
1616
The public, open-source version of this project was published in January 2018. It's current status is: **INCUBATING**
1717

18+
Online demo instance: <https://vboard-demo.herokuapp.com>
19+
1820
![Animated demo showing how to add a pin](vboard_addpin_demo.gif)
1921

2022
<!-- toc -->
@@ -49,7 +51,7 @@ The following command starts V.Board locally :
4951
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --no-build
5052

5153
You can then access the website through http://localhost
52-
and the swagger at http://localhost/api/v1/swagger-ui.html
54+
and the swagger at http://localhost/api/v1/swagger-ui/
5355

5456

5557
# Contributing

bin/heroku_db_cleanup.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
# The URL format needs to be converted in order to be JDBC-compatible:
4+
DB_URL=$(echo $CLEARDB_DATABASE_URL | sed 's~.*//~~')
5+
USER=$(echo $DB_URL | sed 's~:.*~~')
6+
DB_URL=$(echo $DB_URL | sed 's~.*:~~')
7+
PASSWORD=$(echo $DB_URL | sed 's~@.*~~')
8+
DB_URL=$(echo $DB_URL | sed 's~.*@~~')
9+
DB_NAME=$(echo $DB_URL | sed 's~.*/~~')
10+
export DB_NAME=$(echo $DB_NAME | sed 's~[?].*~~')
11+
export DB_URL="jdbc:mysql://$DB_URL&user=$USER&password=$PASSWORD"
12+
13+
WAR_PATH=/app/vboard-ws.war
14+
java -cp $WAR_PATH -Dloader.main=com.vsct.vboard.DBCleaner -Dloader.path=$WAR_PATH!/WEB-INF/classes/,$WAR_PATH!/WEB-INF/ org.springframework.boot.loader.PropertiesLauncher

bin/heroku_start.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
cd /app/static
4+
# Busybox "source" builtin only accepts full paths:
5+
source /app/static/setup_statics.sh
6+
7+
cd /app
8+
# To avoid Heroku R14 warnings, RAM could be further restrained by setting: -Xmx512m
9+
/usr/bin/java -jar -XX:+ExitOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Xms256m -Xmx1g -jar vboard-ws.jar

heroku.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Reference: https://devcenter.heroku.com/articles/build-docker-images-heroku-yml
2+
build:
3+
docker:
4+
web: Dockerfile.heroku
5+
batchs: vboard-batchs/Dockerfile.heroku
6+
run:
7+
web: /app/heroku_start.sh
8+
batchs: /usr/share/logstash/entrypoint.sh
9+
10+
# Addons & configuration required:
11+
# heroku addons:create bonsai:sandbox-6
12+
# heroku config:set VBOARD_ELASTICSEARCH_HOST=https://...bonsaisearch.net:443
13+
# heroku config:set VBOARD_ELASTICSEARCH_INDEX=jdbc_pins_index
14+
# heroku addons:create cleardb:ignite
15+
# The following values can be extracted from $CLEARDB_DATABASE_URL once the addon has been added:
16+
# heroku config
17+
# heroku config:set VBOARD_DB_HOST=...
18+
# heroku config:set MYSQL_USER=...
19+
# heroku config:set MYSQL_ROOT_PASSWORD=...
20+
# heroku config:set MYSQL_DATABASE=...
21+
# Final extra steps required:
22+
# heroku config:set VBOARD_API_ENDPOINT=https://vboard-demo.herokuapp.com
23+
# heroku ps:scale batchs=1
24+
# To configure a daily DB cleanup:
25+
# heroku addons:create scheduler:standard
26+
# To ensure code is pushed to the correct branch:
27+
# git push -f $local_branch heroku:master

vboard-batchs/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ RUN curl https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.48/mysql-
88

99
COPY properties/logstash.conf /usr/share/logstash/pipeline/
1010
COPY properties/logstash.yml /usr/share/logstash/config/
11+
12+
COPY index_mapping.json /usr/share/logstash/
13+
COPY entrypoint.sh /usr/share/logstash/
14+
15+
ENTRYPOINT ["/usr/share/logstash/entrypoint.sh"]

vboard-batchs/Dockerfile.heroku

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Custom Dockerfile for Heroku to use the latest image published on Docker Hub.
2+
# Recipe from: https://stackoverflow.com/a/58204409/636849
3+
FROM vboard/vboard-batchs
4+
5+
# The following could be avoided on next release, when it will already be set in vboard/vboard-batchs:
6+
COPY index_mapping.json /usr/share/logstash/
7+
COPY entrypoint.sh /usr/share/logstash/
8+
9+
ENTRYPOINT ["/usr/share/logstash/entrypoint.sh"]

vboard-batchs/entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o pipefail
3+
4+
# Script initializing the Elasticsearch mapping
5+
6+
while ! curl --fail --silent $VBOARD_ELASTICSEARCH_HOST; do
7+
echo "Elasticsearch endpoint $VBOARD_ELASTICSEARCH_HOST is not yet available - waiting 5s before retrying"
8+
sleep 5
9+
done
10+
11+
echo "Uploading mapping from index_mapping.json:"
12+
# Performing a first call with --verbose to get the error detail in case of failure:
13+
curl --verbose --silent -XPUT $VBOARD_ELASTICSEARCH_HOST/$VBOARD_ELASTICSEARCH_INDEX/_mapping?pretty \
14+
-H 'Content-Type: application/json' -d @index_mapping.json
15+
# Performing a second call with --fail to get a non-zero error code in case of failure, so that the script aborts:
16+
curl --fail --silent -XPUT $VBOARD_ELASTICSEARCH_HOST/$VBOARD_ELASTICSEARCH_INDEX/_mapping?pretty \
17+
-H 'Content-Type: application/json' -d @index_mapping.json
18+
19+
echo "Handing it over to /usr/local/bin/docker-entrypoint"
20+
exec /usr/local/bin/docker-entrypoint "$@"

vboard-batchs/index_mapping.json

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
{
2+
"properties" : {
3+
"@timestamp" : {
4+
"type" : "date"
5+
},
6+
"@version" : {
7+
"type" : "text",
8+
"fields" : {
9+
"keyword" : {
10+
"type" : "keyword",
11+
"ignore_above" : 256
12+
}
13+
}
14+
},
15+
"author" : {
16+
"type" : "text",
17+
"fields" : {
18+
"keyword" : {
19+
"type" : "keyword",
20+
"ignore_above" : 256
21+
}
22+
}
23+
},
24+
"comments_number" : {
25+
"type" : "long"
26+
},
27+
"href_url" : {
28+
"type" : "text",
29+
"fields" : {
30+
"keyword" : {
31+
"type" : "keyword",
32+
"ignore_above" : 256
33+
}
34+
}
35+
},
36+
"img_type" : {
37+
"type" : "text",
38+
"fields" : {
39+
"keyword" : {
40+
"type" : "keyword",
41+
"ignore_above" : 256
42+
}
43+
}
44+
},
45+
"indexable_text_content" : {
46+
"type" : "text",
47+
"fields" : {
48+
"keyword" : {
49+
"type" : "keyword",
50+
"ignore_above" : 256
51+
}
52+
}
53+
},
54+
"labels" : {
55+
"type" : "text",
56+
"fields" : {
57+
"keyword" : {
58+
"type" : "keyword",
59+
"ignore_above" : 256
60+
}
61+
}
62+
},
63+
"likes" : {
64+
"type" : "long"
65+
},
66+
"pin_id" : {
67+
"type" : "text",
68+
"fields" : {
69+
"keyword" : {
70+
"type" : "keyword",
71+
"ignore_above" : 256
72+
}
73+
}
74+
},
75+
"pin_title" : {
76+
"type" : "text",
77+
"fields" : {
78+
"keyword" : {
79+
"type" : "keyword",
80+
"ignore_above" : 256
81+
}
82+
}
83+
},
84+
"post_date" : {
85+
"properties" : {
86+
"after_now" : {
87+
"type" : "boolean"
88+
},
89+
"before_now" : {
90+
"type" : "boolean"
91+
},
92+
"century_of_era" : {
93+
"type" : "long"
94+
},
95+
"chronology" : {
96+
"properties" : {
97+
"zone" : {
98+
"properties" : {
99+
"fixed" : {
100+
"type" : "boolean"
101+
},
102+
"id" : {
103+
"type" : "text",
104+
"fields" : {
105+
"keyword" : {
106+
"type" : "keyword",
107+
"ignore_above" : 256
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
114+
},
115+
"day_of_month" : {
116+
"type" : "long"
117+
},
118+
"day_of_week" : {
119+
"type" : "long"
120+
},
121+
"day_of_year" : {
122+
"type" : "long"
123+
},
124+
"equal_now" : {
125+
"type" : "boolean"
126+
},
127+
"era" : {
128+
"type" : "long"
129+
},
130+
"hour_of_day" : {
131+
"type" : "long"
132+
},
133+
"millis" : {
134+
"type" : "long"
135+
},
136+
"millis_of_day" : {
137+
"type" : "long"
138+
},
139+
"millis_of_second" : {
140+
"type" : "long"
141+
},
142+
"minute_of_day" : {
143+
"type" : "long"
144+
},
145+
"minute_of_hour" : {
146+
"type" : "long"
147+
},
148+
"month_of_year" : {
149+
"type" : "long"
150+
},
151+
"second_of_day" : {
152+
"type" : "long"
153+
},
154+
"second_of_minute" : {
155+
"type" : "long"
156+
},
157+
"week_of_weekyear" : {
158+
"type" : "long"
159+
},
160+
"weekyear" : {
161+
"type" : "long"
162+
},
163+
"year" : {
164+
"type" : "long"
165+
},
166+
"year_of_century" : {
167+
"type" : "long"
168+
},
169+
"year_of_era" : {
170+
"type" : "long"
171+
},
172+
"zone" : {
173+
"properties" : {
174+
"fixed" : {
175+
"type" : "boolean"
176+
},
177+
"id" : {
178+
"type" : "text",
179+
"fields" : {
180+
"keyword" : {
181+
"type" : "keyword",
182+
"ignore_above" : 256
183+
}
184+
}
185+
}
186+
}
187+
}
188+
}
189+
},
190+
"post_date_utc" : {
191+
"type" : "date"
192+
}
193+
}
194+
}

0 commit comments

Comments
 (0)