Skip to content

Commit 40bc137

Browse files
authored
Merge pull request #30 from klakegg/master
Environment variables, Docker images and GitHub workflow
2 parents 7b06b50 + aa0df8d commit 40bc137

File tree

5 files changed

+111
-69
lines changed

5 files changed

+111
-69
lines changed

.github/workflows/maven.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ "main", "master" ]
6+
pull_request:
7+
branches: [ "main", "master" ]
8+
release:
9+
types: [ released ]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Login to GitHub Container Registry
20+
uses: docker/login-action@v3
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Set up JDK
33+
uses: actions/setup-java@v4
34+
with:
35+
java-version: '21'
36+
distribution: corretto
37+
cache: maven
38+
39+
- name: Build with Maven
40+
run: mvn -B --no-transfer-progress clean package
41+
42+
- name: Upload artifact [uber-jar]
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: uber-jar
46+
path: target/*-jar-with-dependencies.jar
47+
if-no-files-found: error
48+
retention-days: 7
49+
50+
- name: Build and push docker image [edge]
51+
run: docker buildx build --push -t ghcr.io/${{ github.repository }}:edge --platform linux/amd64,linux/arm64 .

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Fetch the application jar from the target directory and rename it to application.jar
2+
FROM amazoncorretto:21-al2023-headless AS fetch
3+
4+
COPY target /target
5+
RUN mv /target/*-with-dependencies.jar /target/application.jar
6+
7+
8+
# Actual image to run the application
9+
FROM amazoncorretto:21-al2023-headless
10+
11+
EXPOSE 8082
12+
13+
COPY --from=fetch /target/application.jar /work/application.jar
14+
15+
CMD ["java", "-jar", "/work/application.jar"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ serverPort=<Pick a free port for example 8081>
3838
3939
From project root:
4040
```shell
41-
mvn clean install
41+
mvn clean package
4242
java -jar target/cake-redux-0.1-SNAPSHOT-jar-with-dependencies.jar <config file location>
4343
```
4444

src/main/java/no/javazone/cake/redux/Configuration.java

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import java.io.FileInputStream;
44
import java.io.IOException;
55
import java.time.LocalDate;
6-
import java.time.LocalDateTime;
76
import java.util.HashMap;
87
import java.util.Map;
98
import java.util.Optional;
109

1110
public class Configuration {
1211

1312
private Map<String,String> properties = null;
14-
private static Configuration instance = new Configuration();
13+
private static final Configuration instance = new Configuration();
1514

1615
private Configuration() {
1716

@@ -28,18 +27,24 @@ private static String readConfigFile(String filename) {
2827
}
2928
}
3029

31-
private static String getProperty(String key) {
30+
public static void setProps(Map<String,String> props) {
31+
instance.properties = props;
32+
}
33+
34+
private static String getProperty(String prop, String env) {
3235
if (instance.properties == null) {
3336
instance.loadProps();
3437
if (instance.properties == null) {
35-
throw new IllegalStateException("Properties not initalized getting " +key);
38+
throw new IllegalStateException("Properties not initalized getting " +prop);
3639
}
3740
}
38-
return instance.properties.get(key);
41+
return instance.properties.getOrDefault(prop, System.getenv(env));
3942

4043
}
4144

42-
45+
private static String readConf(String prop, String env, String defaultValue) {
46+
return Optional.ofNullable(getProperty(prop, env)).orElse(defaultValue);
47+
}
4348

4449
private synchronized void loadProps() {
4550
Map<String,String> readProps = new HashMap<>();
@@ -58,169 +63,141 @@ private synchronized void loadProps() {
5863
}
5964

6065
public static String getEmsUser() {
61-
return getProperty("emsUser");
66+
return getProperty("emsUser", "EMS_USER");
6267
}
6368

6469
public static String getEmsPassword() {
65-
return getProperty("emsPassword");
70+
return getProperty("emsPassword", "EMS_PASSWORD");
6671
}
6772

6873
public static String getGoogleClientId() {
69-
return getProperty("googleClientId");
74+
return getProperty("googleClientId", "GOOGLE_CLIENT_ID");
7075
}
7176

7277
public static String getGoogleClientSecret() {
73-
return getProperty("googleClientSecret");
78+
return getProperty("googleClientSecret", "GOOGLE_CLIENT_SECRET");
7479
}
7580

7681
public static String getGoogleRedirectUrl() {
77-
return getProperty("googleRedirectUrl");
82+
return getProperty("googleRedirectUrl", "GOOGLE_REDIRECT_URL");
7883
}
7984

8085
public static String getAutorizedUsers() {
81-
String authorizedUsers = getProperty("authorizedUsers");
86+
String authorizedUsers = getProperty("authorizedUsers", "AUTHORIZED_USERS");
8287
if (authorizedUsers == null) {
8388
return "";
8489
}
8590
return authorizedUsers;
8691
}
8792

8893
public static String autorizedUserFile() {
89-
return getProperty("autorizedUserFile");
94+
return getProperty("autorizedUserFile", "AUTORIZED_USER_FILE");
9095
}
9196

9297
public static String fullUsers() {
93-
return getProperty("fullUsers");
98+
return getProperty("fullUsers", "FULL_USERS");
9499
}
95100

96101
public static boolean noAuthMode() {
97-
return "true".equals(getProperty("noAuthMode"));
102+
return "true".equals(getProperty("noAuthMode", "NO_AUTH_MODE"));
98103
}
99104

100105
public static String emsEventLocation() {
101-
return getProperty("emsEventLocation");
106+
return getProperty("emsEventLocation", "EMS_EVENT_LOCATION");
102107
}
103108

104109
public static String submititLocation() {
105-
return getProperty("submititLocation");
110+
return getProperty("submititLocation", "SUBMITIT_LOCATION");
106111
}
107112

108113
public static Integer serverPort() {
109-
String serverPortStr = getProperty("serverPort");
114+
String serverPortStr = getProperty("serverPort", "SERVER_PORT");
110115
if (serverPortStr == null || serverPortStr.isEmpty()) {
111116
return null;
112117
}
113118
return Integer.parseInt(serverPortStr);
114119
}
115120

116121
public static String mailSenderImplementation() {
117-
return readConf("mailSenderImplementation","smtp");
118-
}
119-
120-
public static String smtpServer() {
121-
return getProperty("smthost");
122-
}
123-
124-
public static int smtpPort() {
125-
return Integer.parseInt(getProperty("smtpport"));
126-
}
127-
128-
public static boolean useMailSSL() {
129-
return "true".equals(getProperty("mailSsl"));
130-
}
131-
132-
public static String mailUser() {
133-
return getProperty("mailUser");
134-
}
135-
136-
public static String mailPassword() {
137-
return getProperty("mailPassword");
122+
return readConf("mailSenderImplementation", "MAIL_SENDER_IMPLEMENTATION","smtp");
138123
}
139124

140125
public static String cakeLocation() {
141-
return getProperty("cakeLocation");
142-
}
143-
144-
private static String readConf(String prop,String defaultValue) {
145-
return Optional.ofNullable(getProperty(prop)).orElse(defaultValue);
126+
return getProperty("cakeLocation", "CAKE_LOCATION");
146127
}
147128

148129
public static boolean whydaSupported() {
149-
return "true".equals(readConf("supportWhyda","false"));
130+
return "true".equals(readConf("supportWhyda", "SUPPORT_WHYDA","false"));
150131
}
151132

152133
public static String logonRedirectUrl() {
153-
return readConf("logonRedirectUrl", "http://localhost:9997/sso/login?redirectURI=http://localhost:8088/admin/");
134+
return readConf("logonRedirectUrl", "LOGON_REDIRECT_URL", "http://localhost:9997/sso/login?redirectURI=http://localhost:8088/admin/");
154135
}
155136

156137
public static String tokenServiceUrl() {
157-
return readConf("tokenServiceUrl", "http://localhost:9998/tokenservice");
138+
return readConf("tokenServiceUrl", "TOKEN_SERIVCE_URL","http://localhost:9998/tokenservice");
158139
}
159140

160141
public static String applicationId() {
161-
return readConf("applicationId", "99");
142+
return readConf("applicationId", "APPLICATION_ID", "99");
162143
}
163144

164145
public static String feedbackStoreFilename() {
165-
return readConf("feedbackStoreFilename",null);
146+
return readConf("feedbackStoreFilename", "FEEDBACK_STORE_FILENAME",null);
166147
}
167148

168-
public static String applicationSecret() { return readConf("applicationSecret", "33879936R6Jr47D4Hj5R6p9qT");}
169-
170-
public static void setProps(Map<String,String> props) {
171-
instance.properties = props;
172-
}
149+
public static String applicationSecret() { return readConf("applicationSecret", "APPLICATION_SECRET", "33879936R6Jr47D4Hj5R6p9qT");}
173150

174151
public static long emailSleepTime() {
175-
return Long.parseLong(readConf("emailSleepTime","5000"));
152+
return Long.parseLong(readConf("emailSleepTime", "EMAIL_SLEEP_TIME","5000"));
176153
}
177154

178155
public static String sleepingPillBaseLocation() {
179-
return readConf("sleepingPillBaseLocation","http://localhost:8082");
156+
return readConf("sleepingPillBaseLocation", "SLEEPINGPILL_BASE_LOCATION","http://localhost:8082");
180157
}
181158

182159
public static String sleepingpillUser() {
183-
return readConf("sleepingpillUser",null);
160+
return readConf("sleepingpillUser", "SLEEPINGPILL_USER",null);
184161
}
185162

186163
public static String sleepingpillPassword() {
187-
return readConf("sleepingpillPassword",null);
164+
return readConf("sleepingpillPassword", "SLEEPINGPILL_PASSWORD",null);
188165
}
189166

190167
public static String feedbackDaoImpl() {
191-
return readConf("feedbackDaoImpl","sleepingpill");
168+
return readConf("feedbackDaoImpl", "FEEDBACK_DAO_IMPL","sleepingpill");
192169
}
193170

194171
public static String videoAdminPassword() {
195-
return readConf("videoAdminPassword","dummy:bingo");
172+
return readConf("videoAdminPassword", "VIDEO_ADMIN_PASSWORD","dummy:bingo");
196173
}
197174

198175
public static String videoAdminConference() {
199-
return readConf("videoAdminConference","30d5c2f1cb214fc8b0649a44fdf3b4bf");
176+
return readConf("videoAdminConference", "VIDEO_ADMIN_CONFERENCE","30d5c2f1cb214fc8b0649a44fdf3b4bf");
200177
}
201178

202179
public static String sendGridKey() {
203-
return readConf("sendGridKey",null);
180+
return readConf("sendGridKey", "SENDGRID_KEY",null);
204181
}
205182

206183
public static String slackAppId() {
207-
return readConf("slackAppId",null);
184+
return readConf("slackAppId", "SLACK_APP_ID", null);
208185
}
209186

210187
public static String slackClientSecret() {
211-
return readConf("slackClientSecret",null);
188+
return readConf("slackClientSecret", "SLACK_CLIENT_SECRET",null);
212189
}
213190

214191
public static String slackAuthChannel() {
215-
return readConf("slackAuthChannel",null);
192+
return readConf("slackAuthChannel", "SLACK_AUTH_CHANNEL",null);
216193
}
217194

218195
public static String slackApiToken() {
219-
return readConf("slackApiToken",null);
196+
return readConf("slackApiToken", "SLACK_API_TOKEN",null);
220197
}
221198

222199
public static LocalDate conferenceWednesday() {
223-
return LocalDate.parse(readConf("conferenceWednesday","2019-09-11"));
200+
return LocalDate.parse(readConf("conferenceWednesday", "CONFERENCE_WEDNESDAY","2019-09-11"));
224201
}
225202

226203

src/test/java/no/javazone/cake/redux/AcceptorSetterTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public void shouldHandleOtherValues() throws Exception {
3636

3737
@Test
3838
public void shouldHandleSlot() throws Exception {
39-
JsonObject roomObj = JsonParser.parseToObject("{\"ref\":\"dgdg\",\"name\":\"Room 5\"}");
4039
JsonObject slotObj = JsonParser.parseToObject("{\"ref\":\"dgdg\",\"start\":\"2017-09-07T13:00\",\"end\":\"2017-09-07T13:20\"}");
4140
JsonObject jsonTalk = JsonFactory.jsonObject().put("slot",slotObj);
4241
String message = acceptorSetter.generateMessage("This is #slot# hoi", null, null, null, null, null, jsonTalk, encodedTalkRef);

0 commit comments

Comments
 (0)