Skip to content

Commit

Permalink
dx: improve makefile, setup docker compose, and allow config for max …
Browse files Browse the repository at this point in the history
…workers (#6)

## Summary

This PR introduces improvements aimed at enhancing the developer
experience (DX):

- **Makefile**: Improved for better usability with clearer and more
understandable commands.
- **Docker Compose Setup**: Added to streamline the development
environment setup, though the database is not included directly in this
setup. Instead, the database configuration is managed by a separate
project [ws-scylla](https://github.com/gvieira18/ws-scylla).
- **Max Workers**: Introduced the ability to specify the maximum number
of workers. If `MAX_WORKERS` is not provided, it defaults to using all
available cores.
- **Additional Improvements**:
  - Added **EditorConfig** for consistent code formatting.
- Simplified versioning by removing `current_schema`, reducing the
annoyance of unnecessary updates every time `make migrate` is run.

> [!NOTE]
> A README about how to set up the system is pending and will be done
later. This could be expanded to cover other services as well.

- basementdevs/twitch-better-profile#54
  • Loading branch information
gvieira18 authored Aug 21, 2024
1 parent e2f5267 commit 8308050
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 787 deletions.
47 changes: 47 additions & 0 deletions .docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ARG DEBIAN_FRONTEND=noninteractive
ARG INIT_PATH=/usr/local/bin/dumb-init
ARG INIT_URL=https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64
ARG USERNAME=rust
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG WORK_DIR=/usr/src/app

FROM rust:1.80.1 AS dev

ARG DEBIAN_FRONTEND
ARG INIT_PATH
ARG INIT_URL
ARG USERNAME
ARG USER_UID
ARG USER_GID
ARG WORK_DIR

ENV TZ=America/Sao_Paulo TERM=xterm-256color LANG=C.UTF-8 LC_ALL=C.UTF-8

SHELL [ "/bin/bash", "-c" ]

RUN set -euxo pipefail;\
apt-get -qq update;\
apt-get -qq install -y nano sudo apt-utils build-essential tzdata curl cmake g++ libpcre3-dev libssl-dev make openssl libgmp-dev git curl ca-certificates software-properties-common wget zip unzip busybox > /dev/null;\
curl --fail --silent --show-error --location ${INIT_URL} --output ${INIT_PATH};\
apt-get -qq clean;\
chmod +x ${INIT_PATH};\
cargo install cargo-watch;

RUN set -euxo pipefail;\
groupadd --gid $USER_GID $USERNAME;\
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME;\
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME;\
chmod 0440 /etc/sudoers.d/$USERNAME;

USER ${USERNAME}

ENV CARGO_HOME="/home/${USERNAME}/.cargo"

WORKDIR $WORK_DIR

EXPOSE 3000

ENTRYPOINT [ "/usr/local/bin/dumb-init", "--" ]

CMD [ "cargo", "watch", "-w", "src", "-x", "run" ]
23 changes: 23 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Exclude version control and IDE files
.git
.github
.idea

# Exclude build artifacts
target

# Exclude environment files
.env*

# Exclude Docker development files
.docker*

# Exclude certificate files
cert.pem
key.pem

# Exclude unnecessary documentation and configuration
README.md

# Exclute test files
tests
29 changes: 29 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
# Adapted from rust-lang/rust repository

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.rs]
max_line_length = 100

[*.md]
# double whitespace at end of line
# denotes a line break in Markdown
trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[Makefile]
indent_style = tab
indent_size = 4
23 changes: 23 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Rust
RUST_LOG=info
RUST_BACKTRACE=1

# Http
MAX_WORKERS=2

# App Config
APP_NAME="Twitch Better Chat API"
APP_VERSION="0.1.0"
APP_URL="0.0.0.0"
APP_PORT="8001"
APP_TLS_ENABLED="false"
APP_TLS_CERT="/your/path/to/cert.pem"
APP_TLS_KEY="/your/path/to/key.pem"
APP_PLATFORM_SECRET="secret"

# Database Config
SCYLLA_NODES="host:port"
SCYLLA_USERNAME=
SCYLLA_PASSWORD=
SCYLLA_CACHED_QUERIES="15"
SCYLLA_KEYSPACE="twitch"
11 changes: 9 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# Rust
RUST_LOG=info
RUST_BACKTRACE=1

# Http
MAX_WORKERS=4

# App Config
APP_NAME="Twitch Better Chat API"
APP_VERSION="0.1.0"
APP_URL="0.0.0.0"
APP_PORT="8001"
APP_TLS_ENABLED="false"
APP_TLS_CERT="/your/path/to/cert.pem"
APP_TLS_KEY="/your/path/to//key.pem"
APP_TLS_KEY="/your/path/to/key.pem"
APP_PLATFORM_SECRET="secret"

# Database Config
SCYLLA_NODES="localhost:9042"
SCYLLA_USERNAME="scylla"
SCYLLA_PASSWORD=""
SCYLLA_PASSWORD=
SCYLLA_CACHED_QUERIES="15"
SCYLLA_KEYSPACE="twitch"
216 changes: 212 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,212 @@
/target
/.idea
.gitignore
.env
# Created by https://www.toptal.com/developers/gitignore/api/rust,linux,macos,windows,jetbrains+all,visualstudiocode,dotenv
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,linux,macos,windows,jetbrains+all,visualstudiocode,dotenv

### dotenv ###
.env
.env.*

# Explicitly track these specific .env files
!.env.example
!.env.docker

# Ignore charybdis-migrate current_schema.json
current_schema.json

### JetBrains+all ###
# 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

# AWS User-specific
.idea/**/aws.xml

# 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

# SonarLint plugin
.idea/sonarlint/

# 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

### JetBrains+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/*

!.idea/codeStyles
!.idea/runConfigurations

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/rust,linux,macos,windows,jetbrains+all,visualstudiocode,dotenv
Loading

0 comments on commit 8308050

Please sign in to comment.