-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from MiSArch/initial-setup
Initial setup of review service
- Loading branch information
Showing
28 changed files
with
1,466 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,8 @@ | ||
apiVersion: dapr.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: pubsub | ||
spec: | ||
type: pubsub.in-memory | ||
version: v1 | ||
metadata: [] |
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,5 @@ | ||
apiVersion: dapr.io/v1alpha1 | ||
kind: Configuration | ||
metadata: | ||
name: daprConfig | ||
namespace: default |
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,43 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose | ||
{ | ||
"name": "Existing Docker Compose (Extend)", | ||
|
||
// Update the 'dockerComposeFile' list if you have more compose files or use different names. | ||
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. | ||
"dockerComposeFile": ["../compose.yaml", "docker-compose.yml"], | ||
|
||
// The 'service' property is the name of the service for the container that VS Code should | ||
// use. Update this value and .devcontainer/docker-compose.yml to the real service name. | ||
"service": "review", | ||
|
||
// The optional 'workspaceFolder' property is the path VS Code should open by default when | ||
// connected. This is typically a file mount in .devcontainer/docker-compose.yml | ||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": ["rust-lang.rust-analyzer"] | ||
} | ||
} | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Uncomment the next line if you want start specific services in your Docker Compose config. | ||
// "runServices": [], | ||
|
||
// Uncomment the next line if you want to keep your containers running after VS Code shuts down. | ||
// "shutdownAction": "none", | ||
|
||
// Uncomment the next line to run commands after the container is created. | ||
// "postCreateCommand": "cat /etc/os-release", | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "devcontainer" | ||
} |
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,25 @@ | ||
version: "3.8" | ||
services: | ||
# Update this to the name of the service you want to work with in your docker-compose.yml file | ||
review: | ||
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer | ||
# folder. Note that the path of the Dockerfile and context is relative to the *primary* | ||
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" | ||
# array). The sample below assumes your primary file is in the root of your project. | ||
# | ||
# build: | ||
# context: . | ||
# dockerfile: .devcontainer/Dockerfile | ||
|
||
volumes: | ||
# Update this to wherever you want VS Code to mount the folder of your project | ||
- ..:/workspaces:cached | ||
|
||
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. | ||
# cap_add: | ||
# - SYS_PTRACE | ||
# security_opt: | ||
# - seccomp:unconfined | ||
|
||
# Overrides default command so things don't shut down after the process ends. | ||
command: /bin/sh -c "while sleep 1000; do :; done" |
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 @@ | ||
target |
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,50 @@ | ||
name: Create and publish a Docker image on Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
tags: | ||
- "v*" | ||
pull_request: | ||
branches: | ||
- "main" | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
|
||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to the Container registry | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: base-dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
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,24 @@ | ||
name: Test update GraphQL schema on pull request | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
schema: | ||
name: Test update GraphQL schema on pull request | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install latest stable | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: "misarch/schemas" | ||
path: "schemas" | ||
- name: Save graphql schemas | ||
run: | | ||
sudo apt install -y protobuf-compiler | ||
cargo run -- --generate-schema |
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,29 @@ | ||
name: Update infrastructure-docker submodule | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
schema: | ||
name: Update infrastructure-docker submodule | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: "misarch/infrastructure-docker" | ||
submodules: true | ||
- name: Update submodule | ||
run: | | ||
cd review | ||
git checkout ${{ github.sha }} | ||
- uses: peter-evans/create-pull-request@v5 | ||
with: | ||
commit-message: Update review schema | ||
branch: update/review | ||
token: ${{ secrets.INFRASTRUCTURE_DOCKER_PUSH_SECRET }} | ||
- name: Set to auto merge | ||
run: gh pr merge update/review --auto --merge -R misarch/infrastructure-docker | ||
env: | ||
GH_TOKEN: ${{ secrets.INFRASTRUCTURE_DOCKER_PUSH_SECRET }} |
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,32 @@ | ||
name: Update GraphQL schema | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
schema: | ||
name: Update GraphQL schema | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install latest stable | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: "misarch/schemas" | ||
path: "schemas" | ||
- name: Save graphql schemas | ||
run: | | ||
sudo apt install -y protobuf-compiler | ||
cargo run -- --generate-schema | ||
- uses: peter-evans/create-pull-request@v5 | ||
with: | ||
path: ./schemas | ||
commit-message: Update review schema | ||
branch: update/review | ||
token: ${{ secrets.SCHEMAS_PUSH_SECRET }} |
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,26 @@ | ||
[package] | ||
name = "misarch-review" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-graphql = { version = "6.0.11", features = ["bson", "chrono", "uuid", "log"] } | ||
async-graphql-axum = "6.0.11" | ||
tokio = { version = "1.8", features = ["macros", "rt-multi-thread"] } | ||
hyper = "1.0.1" | ||
axum = { version = "0.6.0", features = ["headers", "macros"] } | ||
slab = "0.4.2" | ||
mongodb = "2.8.0" | ||
serde = "1.0.193" | ||
futures = "0.3.30" | ||
bson = "2.8.1" | ||
clap = { version = "4.4.13", features = ["derive"] } | ||
uuid = { version = "1.6.1", features = ["v4", "serde"] } | ||
mongodb-cursor-pagination = "0.3.2" | ||
dapr = "0.13.0" | ||
tonic = "0.8" | ||
json = "0.12.4" | ||
log = "0.4.20" | ||
simple_logger = "4.3.3" |
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,33 @@ | ||
# Review service for MiSArch | ||
|
||
### Quickstart (DevContainer) | ||
|
||
1. Open VSCode Development Container | ||
2. `cargo run` starts the GraphQL service + GraphiQL on port `8080` | ||
|
||
### Quickstart (Docker Compose) | ||
|
||
1. `docker compose -f docker-compose-dev.yaml up --build` in the repository root directory. **IMPORTANT:** MongoDB credentials should be configured for production. | ||
|
||
### What it can do | ||
|
||
- CRUD reviews: | ||
|
||
```rust | ||
pub struct Review { | ||
pub id: Uuid, | ||
pub user_id: Uuid, | ||
pub product_variants: HashSet<ProductVariant>, | ||
pub name: String, | ||
pub created_at: DateTime, | ||
pub last_updated_at: DateTime, | ||
} | ||
|
||
/// Foreign ProductVariant | ||
pub struct ProductVariant{ | ||
id: Uuid | ||
} | ||
``` | ||
|
||
- Validates all UUIDs input as strings | ||
- Error prop to GraphQL |
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,27 @@ | ||
# Source: https://github.com/LukeMathWalker/cargo-chef | ||
|
||
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef | ||
WORKDIR /misarch-review | ||
|
||
FROM chef AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
FROM chef AS builder | ||
COPY --from=planner /misarch-review/recipe.json recipe.json | ||
|
||
RUN apt update && apt install -y protobuf-compiler && rm -rf /var/lib/apt/lists/* | ||
|
||
# Build dependencies - this is the caching Docker layer! | ||
RUN cargo chef cook --release --recipe-path recipe.json | ||
# Build application | ||
COPY . . | ||
|
||
RUN cargo build --release --bin misarch-review | ||
|
||
# We do not need the Rust toolchain to run the binary! | ||
FROM debian:bookworm-slim AS runtime | ||
|
||
WORKDIR /misarch-review | ||
COPY --from=builder /misarch-review/target/release/misarch-review /usr/local/bin | ||
ENTRYPOINT ["/usr/local/bin/misarch-review"] |
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,36 @@ | ||
services: | ||
review: | ||
extends: | ||
file: docker-compose-base.yaml | ||
service: review | ||
build: | ||
context: . | ||
dockerfile: devcontainer-dockerfile | ||
ports: | ||
- 8080:8080 | ||
review-db: | ||
extends: | ||
file: docker-compose-base.yaml | ||
service: review-db | ||
review-mongoexpress: | ||
image: mongo-express | ||
ports: | ||
- 8081:8081 | ||
depends_on: | ||
- review-db | ||
environment: | ||
ME_CONFIG_MONGODB_URL: mongodb://review-db:27017 | ||
review-dapr: | ||
extends: | ||
file: docker-compose-base.yaml | ||
service: review-dapr | ||
volumes: | ||
- "./.dapr/dapr-config-minimal.yaml:/config.yaml" | ||
- "./.dapr/components:/components" | ||
placement: | ||
image: "daprio/dapr" | ||
command: ["./placement", "-port", "50006"] | ||
ports: | ||
- 50006:50006 | ||
volumes: | ||
review-db-data: |
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,6 @@ | ||
FROM rust:1.75-slim-bookworm | ||
|
||
WORKDIR /usr/src/misarch-review | ||
|
||
COPY . . | ||
CMD ["cargo", "run"] |
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 @@ | ||
FROM rust:1.75-slim-bookworm | ||
|
||
WORKDIR /usr/src/misarch-review |
Oops, something went wrong.