fix: connect gateway to customer service (#26)
Release package / release (push) Successful in 9m5s

Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com>
Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
2026-04-17 12:03:19 +00:00
parent d91b20357a
commit e07ee318a7
11 changed files with 53 additions and 116 deletions
+17 -23
View File
@@ -1,36 +1,30 @@
FROM ubuntu:26.04 FROM jbangdev/jbang-action:latest AS jbang-provider
FROM node:current-trixie AS base
COPY --from=jbang-provider /jbang /jbang
ENV PATH="/jbang/bin:${PATH}"
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN npm install --global pnpm@latest
# Tránh các câu hỏi tương tác trong quá trình cài đặt # Tránh các câu hỏi tương tác trong quá trình cài đặt
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y ca-certificates && apt-get clean RUN apt-get update && apt-get install -y ca-certificates && apt-get clean
RUN sed -i 's|http://archive.ubuntu.com|https://apt.demonkernel.io.vn|g' /etc/apt/sources.list.d/ubuntu.sources && \
sed -i 's|http://security.ubuntu.com|https://apt.demonkernel.io.vn|g' /etc/apt/sources.list.d/ubuntu.sources
# 1. Cài đặt các công cụ cơ bản # 1. Cài đặt các công cụ cơ bản
RUN apt-get update --fix-missing && apt-get install --no-install-recommends --no-install-suggests -y \ RUN apt-get update --fix-missing && apt-get install --no-install-recommends --no-install-suggests -y \
curl \
bash \
git \ git \
docker-buildx \
docker-cli \
docker.io \ docker.io \
nodejs \ kubectl \
openjdk-25-jdk-headless \ openjdk-25-jdk-headless \
maven maven
# 5. Cấu hình Git RUN jbang trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/
RUN git config --global --add safe.directory '*' RUN jbang app install --fresh --force quarkus@quarkusio
# 2. Cài đặt Node.js & PNPM (thay thế cho apk pnpm)
RUN curl -fsSL https://get.pnpm.io/install.sh | bash -
# 3. Cài đặt Kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
&& install -m 0755 kubectl /usr/local/bin/kubectl
# 6. Cài đặt JBang & Quarkus CLI
ENV JBANG_DIR="/root/.jbang"
ENV PATH="${JBANG_DIR}/bin:${PATH}"
RUN curl -Ls https://sh.jbang.dev | bash -s - trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/
RUN curl -Ls https://sh.jbang.dev | bash -s - app install --fresh --force quarkus@quarkusio
+13 -6
View File
@@ -1,14 +1,19 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the // For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/alpine // README at: https://github.com/devcontainers/templates/tree/main/src/alpine
{ {
"dockerComposeFile": "docker-compose.main.yaml", "build": {
"dockerfile": "Dockerfile",
"args": {
"http_proxy": "http://host.docker.internal:3142"
},
"options": ["--add-host=host.docker.internal:host-gateway"]
},
"runArgs": ["--add-host=host.docker.internal:host-gateway"],
"mounts": [ "mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind", "source=${localEnv:USERPROFILE}/.kube,target=/root/.kube,type=bind",
"source=${localEnv:USERPROFILE}/.kube,target=/root/.kube,type=bind" "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
], ],
"remoteUser": "root", "remoteUser": "root",
"service": "devcontainer",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"customizations": { "customizations": {
"vscode": { "vscode": {
"extensions": [ "extensions": [
@@ -24,7 +29,9 @@
}, },
"containerEnv": { "containerEnv": {
"TESTCONTAINERS_RYUK_DISABLED": "true", "TESTCONTAINERS_RYUK_DISABLED": "true",
"QUARKUS_DEBUG_HOST": "0.0.0.0" "QUARKUS_DEBUG_HOST": "0.0.0.0",
"http_proxy": "http://host.docker.internal:3142"
}, },
"postCreateCommand": "git config --global --add safe.directory '*'",
"forwardPorts": [5005, 8080] "forwardPorts": [5005, 8080]
} }
-29
View File
@@ -1,29 +0,0 @@
services:
kafka:
image: apache/kafka:latest
restart: unless-stopped
network_mode: host
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
kafdrop:
image: obsidiandynamics/kafdrop:latest
restart: unless-stopped
depends_on:
- kafka
network_mode: host
extra_hosts:
- "host.docker.internal:host-gateway"
command: sh -c "sleep 5 && exec ./start-app"
environment:
KAFKA_BROKERCONNECT: "localhost:9092"
-14
View File
@@ -1,14 +0,0 @@
include:
- ./docker-compose.redis.yaml
services:
devcontainer:
build:
context: .
dockerfile: Dockerfile
volumes:
- ../..:/workspaces:cached
network_mode: host
extra_hosts:
- "host.docker.internal:host-gateway"
command: sleep infinity
@@ -1,13 +0,0 @@
services:
postgres:
image: postgres:alpine
environment:
- POSTGRES_PASSWORD=password
network_mode: host
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
-11
View File
@@ -1,11 +0,0 @@
services:
redis:
image: redis:alpine
network_mode: host
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- redis_data:/data
volumes:
redis_data:
@@ -3,21 +3,21 @@ package com.drinkool.services;
import com.drinkool.InternalValue; import com.drinkool.InternalValue;
import com.drinkool.Url; import com.drinkool.Url;
import com.drinkool.models.UserModel; import com.drinkool.models.UserModel;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import jakarta.ws.rs.*; import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import java.util.UUID; import java.util.UUID;
public abstract class BaseService { public abstract class BaseService<T extends UserModel> {
private UserModel model; private final PanacheRepositoryBase<T, UUID> repository;
public BaseService(UserModel model) { protected BaseService(Class<T> entityClass) {
this.model = model; this.repository = new PanacheRepositoryBase<T, UUID>() {};
} }
@SuppressWarnings("static-access") @GET
@POST
@Path(Url.Me) @Path(Url.Me)
@Transactional @Transactional
public Response me(@HeaderParam(InternalValue.userId) UUID id) { public Response me(@HeaderParam(InternalValue.userId) UUID id) {
@@ -25,6 +25,6 @@ public abstract class BaseService {
.entity("InvalidUserId") .entity("InvalidUserId")
.build(); .build();
return Response.ok(model.find("id", id).firstResult()).build(); return Response.ok(repository.findById(id)).build();
} }
} }
@@ -9,13 +9,13 @@ import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*; import jakarta.ws.rs.core.*;
@Path(Role.Customer) @Path(Role.Customer)
public class CustomerService extends BaseService { public class CustomerService extends BaseService<CustomerEntity> {
@Inject @Inject
OtpService otpService; OtpService otpService;
public CustomerService() { public CustomerService() {
super(new CustomerEntity()); super(CustomerEntity.class);
} }
@POST @POST
@@ -29,6 +29,7 @@ public class CustomerService extends BaseService {
return Response.status(Response.Status.CREATED) return Response.status(Response.Status.CREATED)
.header(InternalValue.userId, newCustomer.id.toString()) .header(InternalValue.userId, newCustomer.id.toString())
.header(InternalValue.role, Role.Customer) .header(InternalValue.role, Role.Customer)
.entity(newCustomer)
.build(); .build();
} }
@@ -43,6 +44,7 @@ public class CustomerService extends BaseService {
return Response.status(Response.Status.CREATED) return Response.status(Response.Status.CREATED)
.header(InternalValue.userId, newCustomer.id.toString()) .header(InternalValue.userId, newCustomer.id.toString())
.header(InternalValue.role, Role.Customer) .header(InternalValue.role, Role.Customer)
.entity(newCustomer)
.build(); .build();
} }
@@ -67,6 +69,7 @@ public class CustomerService extends BaseService {
return Response.accepted() return Response.accepted()
.header(InternalValue.userId, customer.id.toString()) .header(InternalValue.userId, customer.id.toString())
.header(InternalValue.role, Role.Customer) .header(InternalValue.role, Role.Customer)
.entity(customer)
.build(); .build();
} }
@@ -87,6 +90,7 @@ public class CustomerService extends BaseService {
return Response.accepted() return Response.accepted()
.header(InternalValue.userId, customer.id.toString()) .header(InternalValue.userId, customer.id.toString())
.header(InternalValue.role, Role.Customer) .header(InternalValue.role, Role.Customer)
.entity(customer)
.build(); .build();
} }
} }
@@ -31,7 +31,7 @@ public class BaseServiceTest {
.header(InternalValue.userId, testUserId) .header(InternalValue.userId, testUserId)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.when() .when()
.post(Role.Customer + Url.Me) .get(Role.Customer + Url.Me)
.then() .then()
.statusCode(200) .statusCode(200)
.body("id", is(testUserId)); .body("id", is(testUserId));
@@ -39,6 +39,6 @@ public class BaseServiceTest {
@Test @Test
public void testMeEndpointWithoutHeader() { public void testMeEndpointWithoutHeader() {
given().when().post(Role.Customer + Url.Me).then().statusCode(400); given().when().get(Role.Customer + Url.Me).then().statusCode(400);
} }
} }
@@ -1,7 +1,9 @@
package com.drinkool; package com.drinkool.controller;
import com.drinkool.Role;
import com.drinkool.Url;
import com.drinkool.dtos.*; import com.drinkool.dtos.*;
import com.drinkool.services.AccountService; import com.drinkool.services.CustomerService;
import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.ws.rs.*; import jakarta.ws.rs.*;
@@ -9,11 +11,11 @@ import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/api/" + Role.Customer) @Path("/api/" + Role.Customer)
class CustomerGatewayResource { public class CustomerController {
@Inject @Inject
@RestClient @RestClient
AccountService accountService; CustomerService accountService;
@POST @POST
@Path(Url.Signup) @Path(Url.Signup)
@@ -10,7 +10,7 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient(configKey = "account") @RegisterRestClient(configKey = "account")
@Path(Role.Customer) @Path(Role.Customer)
public interface AccountService { public interface CustomerService {
@POST @POST
@Path(Url.Signup) @Path(Url.Signup)
Uni<Response> signup(Signup input); Uni<Response> signup(Signup input);
@@ -27,10 +27,7 @@ public interface AccountService {
@Path(Url.QuickLogin) @Path(Url.QuickLogin)
Uni<Response> quickLogin(QuickSignup input); Uni<Response> quickLogin(QuickSignup input);
@POST
@Path(Url.SmsOtp)
Uni<Response> smsOtp(SmsOtp input);
@GET @GET
@Path(Url.Me)
Uni<Response> me(); Uni<Response> me();
} }