Skip to content

Commit

Permalink
Merge pull request #23 from roadster-rs/example
Browse files Browse the repository at this point in the history
Add a minimal example
  • Loading branch information
spencewenski authored Mar 29, 2024
2 parents bdbe2d5 + f66b740 commit 6cefe36
Show file tree
Hide file tree
Showing 18 changed files with 485 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,25 @@ jobs:
- uses: actions/checkout@v4
- name: Formatting
run: cargo fmt -- --check

examples:
name: Examples
runs-on: ubuntu-latest
strategy:
matrix:
# Todo: Is there a way to generate this list automatically?
example:
- minimal
defaults:
run:
working-directory: ./examples/${{matrix.example}}
steps:
- uses: actions/checkout@v4
- name: Test
run: cargo test --no-fail-fast
- name: Check
run: cargo check
- name: Clippy
run: cargo clippy --no-deps -- -D warnings
- name: Formatting
run: cargo fmt -- --check
211 changes: 211 additions & 0 deletions examples/minimal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# tmp files
*~*

env*/
/target
gen/

# Ignore Cargo.lock because this is a lib crate
Cargo.lock

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

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

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
34 changes: 34 additions & 0 deletions examples/minimal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "minimal"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = [".", "entity", "migration"]

[dependencies]
roadster = { version = "0.1", path = "../.." }
tokio = { version = "1.35.1", features = ["full", "macros"] }
anyhow = "1.0.81"
tracing = { version = "0.1.40", features = ["async-await"] }
async-trait = "0.1.77"
aide = { version = "0.13.3", features = ["axum"] }
axum = "0.7.5"

# DB
entity = { path = "entity" }
migration = { path = "migration" }

[dev-dependencies]
cargo-husky = { version = "1.5.0", features = ["default", "run-cargo-check", "run-cargo-clippy", "run-cargo-fmt", "run-cargo-test"] }

[[bin]]
name = "minimal"
path = "./src/main.rs"

[lib]
name = "minimal"
path = "./src/lib.rs"

13 changes: 13 additions & 0 deletions examples/minimal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Minimal Example

# Running locally

```shell
# Set the environment, example:
export ROADSTER.ENVIRONMENT=development
# Start the database and redis (for sidekiq). Note: change the credentials when deploying to prod
docker run -d -p 5432:5432 -e POSTGRES_USER=roadster -e POSTGRES_DB=minimal_dev -e POSTGRES_PASSWORD=roadster postgres:15.3-alpine
docker run -d -p 6379:6379 redis:7.2-alpine
# Start the app
cargo run
```
17 changes: 17 additions & 0 deletions examples/minimal/config/default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[app]
name = "Minimal Example"

[server]
host = "127.0.0.1"
port = 3000

[tracing]
level = "debug"

[database]
auto-migrate = true
connect-timeout = 5000
acquire-timeout = 5000
idle-timeout = 60
min-connections = 0
max-connections = 10
8 changes: 8 additions & 0 deletions examples/minimal/config/development.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[auth.jwt]
secret = "secret-dev"

[database]
uri = "postgres://roadster:roadster@localhost:5432/minimal_dev"

[worker.sidekiq.redis]
uri = "redis://localhost:6379"
8 changes: 8 additions & 0 deletions examples/minimal/config/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[auth.jwt]
secret = "secret-test"

[database]
uri = "postgres://roadster:roadster@localhost:5433/minimal_test"

[worker.sidekiq.redis]
uri = "redis://localhost:6380"
12 changes: 12 additions & 0 deletions examples/minimal/entity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "entity"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
name = "entity"
path = "src/lib.rs"

[dependencies]
sea-orm = "1.0.0-rc.2"
1 change: 1 addition & 0 deletions examples/minimal/entity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

22 changes: 22 additions & 0 deletions examples/minimal/migration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "migration"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
name = "migration"
path = "src/lib.rs"

[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }

[dependencies.sea-orm-migration]
version = "1.0.0-rc.2"
features = [
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
# e.g.
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
"sqlx-postgres", # `DATABASE_DRIVER` feature
]
Loading

0 comments on commit 6cefe36

Please sign in to comment.