Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoApp committed Jan 23, 2024
1 parent db9c84d commit 7103c08
Show file tree
Hide file tree
Showing 241 changed files with 42,149 additions and 20,955 deletions.
40 changes: 39 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
{
"name": "Anythink Development Container",
"image": "public.ecr.aws/v0a2l7y2/wilco/anythink-devcontainer-java:latest"
"image": "public.ecr.aws/v0a2l7y2/wilco/anythink-devcontainer:latest",
"forwardPorts": [3000, 3001, 5433, 27017],
"portsAttributes": {
"3000": {
"label": "Backend",
"elevateIfNeeded": true,
"requireLocalPort": true,
"onAutoForward": "silent"
},
"3001": {
"label": "Frontend",
"elevateIfNeeded": true,
"requireLocalPort": true,
"onAutoForward": "silent"
},
"5433": {
"label": "Database",
"elevateIfNeeded": true,
"requireLocalPort": true,
"onAutoForward": "silent"
},
"27017": {
"label": "Database",
"elevateIfNeeded": true,
"requireLocalPort": true,
"onAutoForward": "silent"
}
},
"postStartCommand": "bash -c .devcontainer/setup.sh",

"settings": {
"extensions.ignoreRecommendations": true,
"workbench.startupEditor": "none",
"workbench.colorTheme": "Visual Studio Dark",
"workbench.colorCustomizations": {},
"workbench.welcomePage.walkthroughs.openOnInstall": false,
"workbench.welcomePage.experimental.videoTutorials": "off",
"github.codespaces.defaultExtensions": []
}
}
29 changes: 29 additions & 0 deletions .devcontainer/open_port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

RETRY_COUNT=3
RETRY_INTERVAL=5
TARGET_PORTS=("3000" "3001")

sleep 5

for port in "${TARGET_PORTS[@]}"; do
for ((try = 1; try <= RETRY_COUNT; try++)); do
echo "Attempt $try: Making port $port public."

gh codespace ports visibility $port:public -c $CODESPACE_NAME
sleep 1

ports_json=$(gh codespace ports -c $CODESPACE_NAME --json label,sourcePort,visibility)
visibility=$(echo "$ports_json" | jq -r ".[] | select(.sourcePort == $port) | .visibility")

if [ "$visibility" == "public" ]; then
echo "Port $port is now public."
break
elif [ $try -lt $RETRY_COUNT ]; then
echo "Port $port is still not public. Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
else
echo "Failed to make port $port public after $RETRY_COUNT attempts."
fi
done
done
10 changes: 10 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
WILCO_ID="`cat .wilco`"
ENGINE_EVENT_ENDPOINT="${ENGINE_BASE_URL}/users/${WILCO_ID}/event"
ENGINE_WILCO_AI_CONFIG="${ENGINE_BASE_URL}/users/${WILCO_ID}/wilcoAiConfig"
CODESPACE_BACKEND_HOST=$(curl -s "${ENGINE_BASE_URL}/api/v1/codespace/backendHost?codespaceName=${CODESPACE_NAME}&portForwarding=${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" | jq -r '.codespaceBackendHost')
CODESPACE_BACKEND_URL="https://${CODESPACE_BACKEND_HOST}"

Expand All @@ -9,8 +10,17 @@ curl -L -X POST "${ENGINE_EVENT_ENDPOINT}" -H "Content-Type: application/json" -
# Export backend envs when in codespaces
echo "export CODESPACE_BACKEND_HOST=\"${CODESPACE_BACKEND_HOST}\"" >> ~/.bashrc
echo "export CODESPACE_BACKEND_URL=\"${CODESPACE_BACKEND_URL}\"" >> ~/.bashrc
echo "export ENGINE_WILCO_AI_URL=\"${ENGINE_WILCO_AI_CONFIG}\"" >> ~/.bashrc
echo "export CODESPACE_WDS_SOCKET_PORT=443" >> ~/.bashrc

# Change backend port visibility to public
echo "(&>/dev/null .devcontainer/open_port.sh &)" >> ~/.bashrc


# Export welcome prompt in bash:
echo "printf \"\n\n☁️☁️☁️️ Anythink: Develop in the Cloud ☁️☁️☁️\n\"" >> ~/.bashrc
echo "printf \"\n=============================================\n\"" >> ~/.bashrc
echo "gh codespace ports -c $CODESPACE_NAME" >> ~/.bashrc
echo "printf \"=============================================\n\"" >> ~/.bashrc
echo "printf \"(Once docker compose is up and running, you can access the frontend and backend using the above urls)\n\"" >> ~/.bashrc
echo "printf \"\n\x1b[31m \x1b[1m👉 Type: \\\`docker compose up\\\` to run the project. 👈\n\n\"" >> ~/.bashrc
36 changes: 8 additions & 28 deletions .github/workflows/wilco-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,26 @@ jobs:
timeout-minutes: 10
name: Pr checks

services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
SECRET_KEY: secret
POSTGRES_DB: anythink-market
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out project
uses: actions/checkout@v2

- name: Use Java
uses: actions/setup-java@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
distribution: "adopt"
java-version: "11"
node-version: "16"

- uses: oNaiPs/secrets-to-env-action@v1
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.6.0
with:
secrets: ${{ toJSON(secrets) }}
mongodb-version: "4.4"

- name: Setup Node for Wilco Checks
uses: actions/setup-node@v3
- uses: oNaiPs/secrets-to-env-action@v1
with:
node-version: "16"
secrets: ${{ toJSON(secrets) }}

- name: Wilco checks
id: Wilco
uses: trywilco/actions@main
with:
engine: ${{ secrets.WILCO_ENGINE_URL }}

- name: Print server logs on failure
if: ${{ failure() }}
run: |
cat /tmp/output.log
12 changes: 12 additions & 0 deletions anythink_ack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
sleep 10s

echo "Welcome to"
echo " _ _ _ _ _ "
echo " / \ _ __ _ _ | |_ | |__ (_) _ __ | | __ "
echo " / _ \ | '_ \ | | | | | __| | '_ \ | | | '_ \ | |/ / "
echo " / ___ \ | | | | | |_| | | |_ | | | | | | | | | | | < "
echo " /_/ \_\ |_| |_| \__, | \__| |_| |_| |_| |_| |_| |_|\_\ "
echo " |___/ "

echo '\n\e]8;;https://app.wilco.gg/chat\e\\Click here\e]8;;\e\\ to go back to Snack'
34 changes: 34 additions & 0 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
env: {
node: true,
},
root: true,
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
ignorePatterns: ["dist/", "node_modules/"],
plugins: ["@typescript-eslint", "jest"],
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
rules: {
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-unused-vars": [
"warn",
{
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
},
overrides: [
{
files: ["test/**/*.ts"],
},
],
};
65 changes: 40 additions & 25 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
.gradle/
/build/
!gradle/wrapper/gradle-wrapper.jar
*.db

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
# Logs
logs
*.log
.DS_Store

npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/

dist

.env
4 changes: 4 additions & 0 deletions backend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
package.json
package-lock.json
tsconfig.json
8 changes: 7 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
FROM public.ecr.aws/v0a2l7y2/wilco/anythink-backend-java:latest
FROM node:18

RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh --output /wait-for-it.sh

RUN chmod +x /wait-for-it.sh

WORKDIR /usr/src/backend
RUN yarn install
9 changes: 0 additions & 9 deletions backend/Dockerfile.aws

This file was deleted.

21 changes: 0 additions & 21 deletions backend/LICENSE

This file was deleted.

36 changes: 2 additions & 34 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
# Anythink Market Backend
# Mongo Chat Server

# How it works

The application uses Spring Boot (Web, Mybatis).

And the code is organized as this:

1. `api` is the web layer implemented by Spring MVC
2. `core` is the business model including entities and services
3. `application` is the high-level services for querying the data transfer objects
4. `infrastructure` contains all the implementation classes as the technique details

# Getting started

You'll need Java 11 installed.

./gradlew bootRun

To test that it works, open a browser tab at http://localhost:3000/api/tags
Alternatively, you can run:

curl http://localhost:3000/api/tags

# Run test

The repository contains a lot of test cases to cover both api test and repository test.

./gradlew test

# Code format

Use spotless for code format.

./gradlew spotlessJavaApply
Based on https://mongodb.github.io/chatbot/server/configure
Loading

0 comments on commit 7103c08

Please sign in to comment.