Skip to content

Commit

Permalink
Merge pull request #49 from datasektionen/docker
Browse files Browse the repository at this point in the history
Add Dockerfile
  • Loading branch information
foodelevator authored Sep 21, 2023
2 parents 30d59ea + 9d348eb commit f970768
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
out
*.iml
.DS_Store
.env
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM amazoncorretto:11-alpine3.18 AS base

WORKDIR /app

FROM base AS builder

RUN apk add maven

COPY pom.xml system.properties ./

RUN mvn -DskipTests clean dependency:list install

COPY src src

RUN mvn -DskipTests clean dependency:list install

FROM base AS runner

COPY --from=builder /app/target/calypso-1.0-SNAPSHOT.jar .

CMD ["java", "-jar", "calypso-1.0-SNAPSHOT.jar"]
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.8"
services:
db:
image: postgres:16-alpine3.18
environment:
POSTGRES_PASSWORD: calypso

web:
build: .
environment:
JDBC_DATABASE_URL: "jdbc:postgresql://db:5432/postgres"
JDBC_DATABASE_USERNAME: postgres
JDBC_DATABASE_PASSWORD: calypso
APPLICATION_URL: http://localhost.datasektionen.se:3000
env_file: .env
ports:
- "3000:8080"
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DAuthEntryPoint(Config config) {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException {
response.sendRedirect("https://login.datasektionen.se/login?callback=" +
response.sendRedirect(config.getLoginUrl() + "/login?callback=" +
config.getBaseUrl() + "/auth/verify?token=");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DAuthUserDetailsService(Config config) {
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
// Required variables
var t = token.getPrincipal().toString();
var url = "https://login.datasektionen.se/verify/" + t + ".json?api_key=" + config.getApiKey();
var url = config.getLoginUrl() + "/verify/" + t + ".json?api_key=" + config.getLoginApiKey();

var headers = new HttpHeaders();
headers.set("User-Agent", "Spring Framework/Java " + System.getProperty("java.version"));
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/se/datasektionen/calypso/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
@Component
@Getter
public class Config {

private final String baseUrl;
private final String apiKey;
private final String loginApiKey;
private final String loginUrl;

public Config(@Value("${APPLICATION_URL}") String baseUrl, @Value("${LOGIN_KEY}") String apiKey) {
public Config(
@Value("${APPLICATION_URL}") String baseUrl,
@Value("${LOGIN_KEY}") String loginApiKey,
@Value("${LOGIN_URL:https://login.datasektionen.se}") String loginUrl
) {
this.baseUrl = baseUrl;
this.apiKey = apiKey;
this.loginApiKey = loginApiKey;
this.loginUrl = loginUrl;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
{
"name": "LOGIN_KEY",
"type": "java.lang.String",
"description": "API key for login.datasektionen.se."
"description": "API key for login."
},
{
"name": "LOGIN_URL",
"type": "java.lang.String",
"description": "URL to login."
}
]
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ spring.jpa.generate-ddl=true
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
server.port=${PORT:8080}
server.port=${PORT:8080}

0 comments on commit f970768

Please sign in to comment.