Skip to content

Commit 02cb152

Browse files
committed
Update Dockerfile and docker-compose.yml, add environment variables and change port mapping
Remove unused imports and commented code Update application.properties with correct bootstrap host
1 parent ccf727f commit 02cb152

File tree

7 files changed

+114
-45
lines changed

7 files changed

+114
-45
lines changed

Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# # # Stage 1: Build Couchbase Server
2+
# # FROM couchbase AS couchbase-build
3+
# # RUN chmod +x /entrypoint.sh
4+
# # COPY configure-server.sh /opt/couchbase
5+
# # RUN chmod +x /opt/couchbase/configure-server.sh
6+
7+
# # Stage 2: Build Java Spring Boot Application
8+
# FROM eclipse-temurin:17-jdk-jammy AS java-app-build
9+
# ENV HOME=/usr/app
10+
# RUN mkdir -p "$HOME"
11+
# WORKDIR "$HOME"
12+
# COPY . "$HOME"
13+
# RUN --mount=type=cache,target=/root/.m2 ./mvnw -f "$HOME"/pom.xml clean package -DskipTests=true
14+
15+
# # Stage 3: Final Image
16+
# FROM eclipse-temurin:17-jre-jammy
17+
18+
# # Copy artifacts from the Couchbase build stage
19+
# COPY --from=couchbase-build /opt/couchbase /opt/couchbase
20+
21+
# # Copy artifacts from the Java Spring Boot application build stage
22+
# ARG JAR_FILE=/usr/app/target/*.jar
23+
# COPY --from=java-app-build $JAR_FILE /app/runner.jar
24+
25+
# # Expose ports
26+
# EXPOSE 8080
27+
# EXPOSE 8091
28+
# EXPOSE 8092
29+
# EXPOSE 8093
30+
# EXPOSE 8094
31+
# EXPOSE 8095
32+
# EXPOSE 8096
33+
# EXPOSE 11207
34+
# EXPOSE 11210
35+
# EXPOSE 11211
36+
# EXPOSE 18091
37+
# EXPOSE 18092
38+
# EXPOSE 18093
39+
# EXPOSE 18094
40+
# EXPOSE 18095
41+
# EXPOSE 18096
42+
43+
# # Entrypoint
44+
# ENTRYPOINT java -jar /app/runner.jar
45+
46+
47+
FROM eclipse-temurin:17-jdk-jammy AS build
48+
ENV HOME=/usr/app
49+
RUN mkdir -p "$HOME"
50+
WORKDIR "$HOME"
51+
COPY . "$HOME"
52+
RUN --mount=type=cache,target=/root/.m2 ./mvnw -f "$HOME"/pom.xml clean package -DskipTests=true
53+
54+
#
55+
# Package stage
56+
#
57+
FROM eclipse-temurin:17-jre-jammy
58+
ARG JAR_FILE=/usr/app/target/*.jar
59+
COPY --from=build $JAR_FILE /app/runner.jar
60+
EXPOSE 8080
61+
ENTRYPOINT java -jar /app/runner.jar

Dockerfile-couchbase-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ RUN chmod +x /entrypoint.sh
44
COPY configure-server.sh /opt/couchbase
55
RUN chmod +x /opt/couchbase/configure-server.sh
66

7-
# CMD ["/opt/couchbase/configure-server.sh"]
7+
CMD ["/opt/couchbase/configure-server.sh"]

docker-compose.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ services:
77
dockerfile: Dockerfile-couchbase-server
88
container_name: couchbase
99
ports:
10-
- 9091-9094:8091-8094
11-
- 21210:11210
10+
- "9091-9094:8091-8094"
11+
- "21210:11210"
12+
environment:
13+
CLUSTER_USERNAME: Administrator
14+
CLUSTER_PASSWORD: password
15+
CLUSTER_NAME: default
16+
SERVICES: data,index,query,fts
17+
CLUSTER_RAMSIZE: 500
18+
BUCKET: travel-sample
19+
BUCKET_RAMSIZE: 300
20+
NODE_INIT_INDEX_PATH: /opt/couchbase/var/lib/couchbase/indexes
1221
volumes:
1322
- .docker/couchbase:/opt/couchbase/var
1423

@@ -20,7 +29,7 @@ services:
2029
dockerfile: Dockerfile-java-springboot-quickstart
2130
container_name: java-springboot-quickstart
2231
ports:
23-
- 8080:8080
32+
- 9090:8080
2433
depends_on:
2534
- couchbase
2635
networks:

src/main/java/org/couchbase/quickstart/springboot/configs/DBProperties.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ public class DBProperties {
2020
@Value("${spring.couchbase.bucket.scope}")
2121
private String scopeName;
2222

23-
2423
}

src/main/java/org/couchbase/quickstart/springboot/configs/Swagger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.couchbase.quickstart.springboot.configs;
22

3-
import org.couchbase.quickstart.springboot.controllers.ProfileController;
43
import org.springframework.context.annotation.Bean;
54
import org.springframework.context.annotation.Configuration;
65

@@ -15,7 +14,8 @@ public class Swagger {
1514
public Docket api() {
1615
return new Docket(DocumentationType.SWAGGER_2)
1716
.select()
18-
.apis(RequestHandlerSelectors.basePackage(ProfileController.class.getPackage().getName()))
17+
.apis(RequestHandlerSelectors.basePackage(
18+
"org.couchbase.quickstart.springboot.controllers"))
1919
.paths(PathSelectors.any())
2020
.build();
2121
}

src/main/java/org/couchbase/quickstart/springboot/runners/DBSetupRunner.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,46 @@ public class DBSetupRunner implements CommandLineRunner {
3030

3131
@Override
3232
public void run(String... args) {
33-
try {
34-
cluster.queryIndexes().createPrimaryIndex(props.getBucketName());
35-
System.out.println("Created primary index" + props.getBucketName());
36-
} catch (Exception e) {
37-
System.out.println("Primary index already exists on bucket "+props.getBucketName());
38-
}
33+
// try {
34+
// cluster.queryIndexes().createPrimaryIndex(props.getBucketName());
35+
// System.out.println("Created primary index" + props.getBucketName());
36+
// } catch (Exception e) {
37+
// System.out.println("Primary index already exists on bucket "+props.getBucketName());
38+
// }
3939

40-
CollectionManager collectionManager = bucket.collections();
41-
try {
42-
CollectionSpec spec = CollectionSpec.create(CollectionNames.PROFILE, bucket.defaultScope().name());
43-
collectionManager.createCollection(spec);
44-
System.out.println("Created collection '" + spec.name() + "' in scope '" + spec.scopeName() + "' of bucket '" + bucket.name() + "'");
45-
Thread.sleep(1000);
46-
} catch (CollectionExistsException e){
47-
System.out.println(String.format("Collection <%s> already exists", CollectionNames.PROFILE));
48-
} catch (Exception e) {
49-
System.out.println(String.format("Generic error <%s>",e.getMessage()));
50-
}
40+
// CollectionManager collectionManager = bucket.collections();
41+
// try {
42+
// CollectionSpec spec = CollectionSpec.create(CollectionNames.PROFILE, bucket.defaultScope().name());
43+
// collectionManager.createCollection(spec);
44+
// System.out.println("Created collection '" + spec.name() + "' in scope '" + spec.scopeName() + "' of bucket '" + bucket.name() + "'");
45+
// Thread.sleep(1000);
46+
// } catch (CollectionExistsException e){
47+
// System.out.println(String.format("Collection <%s> already exists", CollectionNames.PROFILE));
48+
// } catch (Exception e) {
49+
// System.out.println(String.format("Generic error <%s>",e.getMessage()));
50+
// }
5151

52-
try {
53-
final String query = "CREATE PRIMARY INDEX default_profile_index ON "+props.getBucketName()+"._default."+ CollectionNames.PROFILE;
54-
System.out.println(String.format("Creating default_profile_index: <%s>", query));
55-
final QueryResult result = cluster.query(query);
56-
for (JsonObject row : result.rowsAsObject()){
57-
System.out.println(String.format("Index Creation Status %s",row.getObject("meta").getString("status")));
58-
}
59-
System.out.println("Created primary index on collection " + CollectionNames.PROFILE);
60-
Thread.sleep(1000);
61-
} catch (IndexExistsException e){
62-
System.out.println(String.format("Collection's primary index already exists"));
63-
} catch (Exception e){
64-
System.out.println(String.format("General error <%s> when trying to create index ",e.getMessage()));
65-
}
52+
// try {
53+
// final String query = "CREATE PRIMARY INDEX default_profile_index ON "+props.getBucketName()+"._default."+ CollectionNames.PROFILE;
54+
// System.out.println(String.format("Creating default_profile_index: <%s>", query));
55+
// final QueryResult result = cluster.query(query);
56+
// for (JsonObject row : result.rowsAsObject()){
57+
// System.out.println(String.format("Index Creation Status %s",row.getObject("meta").getString("status")));
58+
// }
59+
// System.out.println("Created primary index on collection " + CollectionNames.PROFILE);
60+
// Thread.sleep(1000);
61+
// } catch (IndexExistsException e){
62+
// System.out.println(String.format("Collection's primary index already exists"));
63+
// } catch (Exception e){
64+
// System.out.println(String.format("General error <%s> when trying to create index ",e.getMessage()));
65+
// }
6666

67-
try {
68-
final QueryResult result = cluster.query("CREATE INDEX default_profile_firstName_index ON " + props.getBucketName() + "._default." + CollectionNames.PROFILE + "(firstName)");
69-
Thread.sleep(1000);
70-
} catch (Exception e) {
71-
System.out.println(String.format("Failed to create secondary index on profile.firstName: %s", e.getMessage()));
72-
}
67+
// try {
68+
// final QueryResult result = cluster.query("CREATE INDEX default_profile_firstName_index ON " + props.getBucketName() + "._default." + CollectionNames.PROFILE + "(firstName)");
69+
// Thread.sleep(1000);
70+
// } catch (Exception e) {
71+
// System.out.println(String.format("Failed to create secondary index on profile.firstName: %s", e.getMessage()));
72+
// }
7373

7474
System.out.println("Application is ready.");
7575
}

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
spring.couchbase.bootstrap-hosts=localhost
1+
spring.couchbase.bootstrap-hosts=host.docker.internal
22
spring.couchbase.bucket.name=travel-sample
33
spring.couchbase.bucket.user=kaustav
44
spring.couchbase.bucket.scope=inventory

0 commit comments

Comments
 (0)