-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1327 from cambridge-cares/1771-dev-user-agent
1771 dev user agent
- Loading branch information
Showing
22 changed files
with
919 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Dockerfile | ||
docker-compose.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*log4j2.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<settingsSecurity> | ||
<master>MASTER_PASSWORD</master> | ||
</settingsSecurity> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<settings> | ||
<!-- The path to the local repository Maven will use to store artifacts --> | ||
<localRepository>${user.home}/.m2/repository</localRepository> | ||
|
||
<!-- Will Maven prompt you when it needs input? If false, Maven will use a sensible default --> | ||
<interactiveMode>false</interactiveMode> | ||
|
||
<!-- Should Maven use the plugin-registry.xml to manage plugin version? --> | ||
<usePluginRegistry>false</usePluginRegistry> | ||
|
||
<!-- Should Maven operate in offline mode? --> | ||
<offline>false</offline> | ||
|
||
<!-- Server credentials --> | ||
<servers> | ||
<server> | ||
<id>repo</id> | ||
<username>REPO_USERNAME</username> | ||
<password>REPO_PASSWORD</password> | ||
</server> | ||
</servers> | ||
|
||
<profiles> | ||
<profile> | ||
<id>Default Profile</id> | ||
<properties></properties> | ||
<repositories> | ||
<repository> | ||
<id>repo</id> | ||
<url>https://maven.pkg.github.com/cambridge-cares/TheWorldAvatar/</url> | ||
<layout>default</layout> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
</profile> | ||
</profiles> | ||
|
||
<!-- List of profiles that are active for all builds. --> | ||
<activeProfiles> | ||
<activeProfile>Default Profile</activeProfile> | ||
</activeProfiles> | ||
</settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# First stage: build war file | ||
#================================================================================================== | ||
FROM maven:3.6-openjdk-11-slim as builder | ||
|
||
# Copy all files into root's home, including the source, pom file, ./m2 directory and credentials | ||
ADD . /root | ||
|
||
# Populate settings templates with credentials, repo name | ||
WORKDIR /root/.m2 | ||
# (Note that | rather than / is used as the sed delimiter, since encrypted passwords can contain the latter, but not the former | ||
RUN sed -i "s|MASTER_PASSWORD|$(mvn --encrypt-master-password master_password)|" settings-security.xml | ||
RUN sed -i "s|REPO_USERNAME|$(cat ../credentials/repo_username.txt)|;s|REPO_PASSWORD|$(cat ../credentials/repo_password.txt|xargs mvn --encrypt-password)|" settings.xml | ||
|
||
|
||
# Build | ||
WORKDIR /root/UserAgent | ||
RUN --mount=type=cache,target=/root/.m2/repository mvn clean package | ||
#================================================================================================== | ||
|
||
# Second stage: copy the downloaded dependency into a new image and build into an app | ||
#================================================================================================== | ||
FROM tomcat:9.0 as agent | ||
|
||
WORKDIR /root/UserAgent | ||
|
||
# #================================================================================================== | ||
# Copy the compiled jar from the builder | ||
COPY --from=builder /root/UserAgent/output/user-agent##*.war $CATALINA_HOME/webapps/ | ||
COPY ./docker/entrypoint.sh entrypoint.sh | ||
|
||
# Port for Java debugging | ||
EXPOSE 5005 | ||
|
||
ENTRYPOINT ["./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# UserAgent | ||
## 1. Description | ||
UserAgent is an agent that manages TWA user with other services account or devices (e.g. smartphones). It currently supports the following functions through the endpoints: | ||
- `/registerPhone`: register a new phone with the user | ||
- `/getPhoneIds`: get the phone ids of the user | ||
- `/status`: get the status of the agent. Used for testing. | ||
|
||
## 2. Requirements | ||
Launch stack with the default containers and the following additional containers: | ||
- keycloak | ||
|
||
## 3. Deploy | ||
### 3.1 Retrieving UserAgent's image | ||
The UserAgent should be pulled automatically with the stack-manager, if not you can pull the latest version from [cambridge_cares package](https://github.com/orgs/cambridge-cares/packages/container/package/user-agent) using `docker pull ghcr.io/cambridge-cares/user-agent:<LATEST-VERSION>` | ||
|
||
### 3.2 Starting with the stack-manager | ||
The agent has been implemented to work in the stack, which requires the UserAgent Docker container to be deployed in the stack. To do so, place [user-agent.json](stack-manager-config/inputs/config/services/user-agent.json) in the [stack-manager config directory]. | ||
|
||
Then, run `./stack.sh start <STACK NAME>` in the [stack-manager](https://github.com/cambridge-cares/TheWorldAvatar/tree/main/Deploy/stacks/dynamic/stack-manager) main folder. This will spin up the agent in the stack. | ||
|
||
## 4. Build and debug | ||
## 4.1 Credentials | ||
The docker image uses TheWorldAvatar maven repository (`https://maven.pkg.github.com/cambridge-cares/TheWorldAvatar/`). | ||
You will need to provide your credentials (GitHub username/personal access token) in single-word text files as follows: | ||
``` | ||
./credentials/ | ||
repo_username.txt | ||
repo_password.txt | ||
``` | ||
|
||
### 4.2 Building Docker Image | ||
In the same directory as this README, run `./stack.sh build`. This will build the TrajectoryQueryAgent local Docker Image. | ||
|
||
### 4.2 Spinning up with stack-manager | ||
To debug the agent, replace [`user-agent-debug.json`](stack-manager-config/inputs/config/services/user-agent-debug.json) instead of [`user-agent.json`](stack-manager-config/inputs/config/services/user-agent.json) in the [stack-manager config directory]. | ||
|
||
Spin up with `./stack.sh start <STACK NAME>` in the [stack-manager]'s main folder. | ||
The debugger port will be available at 5005. | ||
|
||
[stack-manager]: https://github.com/cambridge-cares/TheWorldAvatar/tree/main/Deploy/stacks/dynamic/stack-manager | ||
[stack-manager config directory]: https://github.com/cambridge-cares/TheWorldAvatar/tree/main/Deploy/stacks/dynamic/stack-manager/inputs/config/services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" metadata-complete="false" version="3.1"> | ||
<display-name>UserAgent</display-name> | ||
<description>A java agent for manage user related data.</description> | ||
|
||
<servlet> | ||
<servlet-name>UserAgent</servlet-name> | ||
<servlet-class>uk.ac.cam.cares.jps.agent</servlet-class> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>UserAgent</servlet-name> | ||
<url-pattern>/</url-pattern> | ||
</servlet-mapping> | ||
|
||
|
||
</web-app> |
Oops, something went wrong.