-
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.
- Loading branch information
0 parents
commit d75903c
Showing
62 changed files
with
1,294 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 @@ | ||
1.13.2 |
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,88 @@ | ||
name: converge CI | ||
|
||
on: | ||
push: | ||
branches: "*" | ||
pull_request: | ||
branches: "*" | ||
|
||
jobs: | ||
check-format: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
crystal_version: | ||
- 1.13.2 | ||
experimental: | ||
- false | ||
runs-on: ubuntu-latest | ||
continue-on-error: ${{ matrix.experimental }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Crystal | ||
uses: crystal-lang/install-crystal@v1 | ||
with: | ||
crystal: ${{ matrix.crystal_version }} | ||
- name: Format | ||
run: crystal tool format --check | ||
|
||
specs: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
crystal_version: | ||
- 1.13.2 | ||
experimental: | ||
- false | ||
runs-on: ubuntu-latest | ||
env: | ||
LUCKY_ENV: test | ||
DB_HOST: localhost | ||
continue-on-error: ${{ matrix.experimental }} | ||
services: | ||
postgres: | ||
image: postgres:14-alpine | ||
env: | ||
POSTGRES_PASSWORD: postgres | ||
ports: | ||
- 5432:5432 | ||
# Set health checks to wait until postgres has started | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Crystal | ||
uses: crystal-lang/install-crystal@v1 | ||
with: | ||
crystal: ${{ matrix.crystal_version }} | ||
|
||
- name: Set up Crystal cache | ||
uses: actions/cache@v4 | ||
id: crystal-cache | ||
with: | ||
path: | | ||
~/.cache/crystal | ||
lib | ||
key: ${{ runner.os }}-crystal-${{ hashFiles('**/shard.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-crystal- | ||
- name: Install shards | ||
if: steps.crystal-cache.outputs.cache-hit != 'true' | ||
run: shards check || shards install | ||
|
||
- name: Build lucky_tasks | ||
run: crystal build tasks.cr -o ./lucky_tasks | ||
|
||
- name: Prepare database | ||
run: | | ||
./lucky_tasks db.create | ||
./lucky_tasks db.migrate | ||
./lucky_tasks db.seed.required_data | ||
- name: Run tests | ||
run: crystal spec |
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,10 @@ | ||
/docs/ | ||
/lib/ | ||
/bin/ | ||
/.shards/ | ||
*.dwarf | ||
start_server | ||
*.dwarf | ||
*.local.cr | ||
.env | ||
/tmp |
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 @@ | ||
web: bin/app | ||
release: lucky db.migrate |
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 @@ | ||
system_check: script/system_check && sleep 100000 | ||
web: lucky watch |
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,23 @@ | ||
# converge | ||
|
||
This is a project written using [Lucky](https://luckyframework.org). Enjoy! | ||
|
||
### Setting up the project | ||
|
||
1. [Install required dependencies](https://luckyframework.org/guides/getting-started/installing#install-required-dependencies) | ||
1. Update database settings in `config/database.cr` | ||
1. Run `script/setup` | ||
1. Run `lucky dev` to start the app | ||
|
||
### Using Docker for development | ||
|
||
1. [Install Docker](https://docs.docker.com/engine/install/) | ||
1. Run `docker compose up` | ||
|
||
The Docker container will boot all of the necessary components needed to run your Lucky application. | ||
To configure the container, update the `docker-compose.yml` file, and the `docker/development.dockerfile` file. | ||
|
||
|
||
### Learning Lucky | ||
|
||
Lucky uses the [Crystal](https://crystal-lang.org) programming language. You can learn about Lucky from the [Lucky Guides](https://luckyframework.org/guides/getting-started/why-lucky). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
# This file may be used for custom Application configurations. | ||
# It will be loaded before other config files. | ||
# | ||
# Read more on configuration: | ||
# https://luckyframework.org/guides/getting-started/configuration#configuring-your-own-code | ||
|
||
# Use this code as an example: | ||
# | ||
# ``` | ||
# module Application | ||
# Habitat.create do | ||
# setting support_email : String | ||
# setting lock_with_basic_auth : Bool | ||
# end | ||
# end | ||
# | ||
# Application.configure do |settings| | ||
# settings.support_email = "support@myapp.io" | ||
# settings.lock_with_basic_auth = LuckyEnv.staging? | ||
# end | ||
# | ||
# # In your application, call | ||
# # `Application.settings.support_email` anywhere you need it. | ||
# ``` |
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,4 @@ | ||
# This enables the color output when in development or test | ||
# Check out the Colorize docs for more information | ||
# https://crystal-lang.org/api/Colorize.html | ||
Colorize.enabled = LuckyEnv.development? || LuckyEnv.test? |
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 @@ | ||
require "./server" | ||
|
||
Lucky::Session.configure do |settings| | ||
settings.key = "_converge_session" | ||
end | ||
|
||
Lucky::CookieJar.configure do |settings| | ||
settings.on_set = ->(cookie : HTTP::Cookie) { | ||
# If ForceSSLHandler is enabled, only send cookies over HTTPS | ||
cookie.secure(Lucky::ForceSSLHandler.settings.enabled) | ||
|
||
# By default, don't allow reading cookies with JavaScript | ||
cookie.http_only(true) | ||
|
||
# Restrict cookies to a first-party or same-site context | ||
cookie.samesite(:lax) | ||
|
||
# Set all cookies to the root path by default | ||
cookie.path("/") | ||
|
||
# You can set other defaults for cookies here. For example: | ||
# | ||
# cookie.expires(1.year.from_now).domain("mydomain.com") | ||
} | ||
end |
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 @@ | ||
database_name = "converge_#{LuckyEnv.environment}" | ||
|
||
AppDatabase.configure do |settings| | ||
if LuckyEnv.production? | ||
settings.credentials = Avram::Credentials.parse(ENV["DATABASE_URL"]) | ||
else | ||
settings.credentials = Avram::Credentials.parse?(ENV["DATABASE_URL"]?) || Avram::Credentials.new( | ||
database: database_name, | ||
hostname: ENV["DB_HOST"]? || "localhost", | ||
port: ENV["DB_PORT"]?.try(&.to_i) || 5432, | ||
# Some common usernames are "postgres", "root", or your system username (run 'whoami') | ||
username: ENV["DB_USERNAME"]? || "postgres", | ||
# Some Postgres installations require no password. Use "" if that is the case. | ||
password: ENV["DB_PASSWORD"]? || "postgres" | ||
) | ||
end | ||
end | ||
|
||
Avram.configure do |settings| | ||
settings.database_to_migrate = AppDatabase | ||
|
||
# In production, allow lazy loading (N+1). | ||
# In development and test, raise an error if you forget to preload associations | ||
settings.lazy_load_enabled = LuckyEnv.production? | ||
|
||
# Always parse `Time` values with these specific formats. | ||
# Used for both database values, and datetime input fields. | ||
# settings.time_formats << "%F" | ||
end |
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 @@ | ||
require "carbon_sendgrid_adapter" | ||
|
||
BaseEmail.configure do |settings| | ||
if LuckyEnv.production? | ||
# If you don't need to send emails, set the adapter to DevAdapter instead: | ||
# | ||
# settings.adapter = Carbon::DevAdapter.new | ||
# | ||
# If you do need emails, get a key from SendGrid and set an ENV variable | ||
send_grid_key = send_grid_key_from_env | ||
settings.adapter = Carbon::SendGridAdapter.new(api_key: send_grid_key) | ||
elsif LuckyEnv.development? | ||
settings.adapter = Carbon::DevAdapter.new(print_emails: true) | ||
else | ||
settings.adapter = Carbon::DevAdapter.new | ||
end | ||
end | ||
|
||
private def send_grid_key_from_env | ||
ENV["SEND_GRID_KEY"]? || raise_missing_key_message | ||
end | ||
|
||
private def raise_missing_key_message | ||
puts "Missing SEND_GRID_KEY. Set the SEND_GRID_KEY env variable to 'unused' if not sending emails, or set the SEND_GRID_KEY ENV var.".colorize.red | ||
exit(1) | ||
end |
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 @@ | ||
# Environments are managed using `LuckyEnv`. By default, development, production | ||
# and test are supported. See | ||
# https://luckyframework.org/guides/getting-started/configuration for details. | ||
# | ||
# The default environment is development unless the environment variable | ||
# LUCKY_ENV is set. | ||
# | ||
# Example: | ||
# ``` | ||
# LuckyEnv.environment # => "development" | ||
# LuckyEnv.development? # => true | ||
# LuckyEnv.production? # => false | ||
# LuckyEnv.test? # => false | ||
# ``` | ||
# | ||
# New environments can be added using the `LuckyEnv.add_env` macro. | ||
# | ||
# Example: | ||
# ``` | ||
# LuckyEnv.add_env :staging | ||
# LuckyEnv.staging? # => false | ||
# ``` | ||
# | ||
# To determine whether or not a `LuckyTask` is currently running, you can use | ||
# the `LuckyEnv.task?` predicate. | ||
# | ||
# Example: | ||
# ``` | ||
# LuckyEnv.task? # => false | ||
# ``` | ||
|
||
# Add a staging environment. | ||
# LuckyEnv.add_env :staging |
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 @@ | ||
Lucky::ErrorHandler.configure do |settings| | ||
settings.show_debug_output = !LuckyEnv.production? | ||
end |
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 @@ | ||
require "file_utils" | ||
|
||
if LuckyEnv.test? | ||
# Logs to `tmp/test.log` so you can see what's happening without having | ||
# a bunch of log output in your spec results. | ||
FileUtils.mkdir_p("tmp") | ||
|
||
backend = Log::IOBackend.new(File.new("tmp/test.log", mode: "w")) | ||
backend.formatter = Lucky::PrettyLogFormatter.proc | ||
Log.dexter.configure(:debug, backend) | ||
elsif LuckyEnv.production? | ||
# Lucky uses JSON in production so logs can be searched more easily | ||
# | ||
# If you want logs like in develpoment use 'Lucky::PrettyLogFormatter.proc'. | ||
backend = Log::IOBackend.new | ||
backend.formatter = Dexter::JSONLogFormatter.proc | ||
Log.dexter.configure(:info, backend) | ||
else | ||
# Use a pretty formatter printing to STDOUT in development | ||
backend = Log::IOBackend.new | ||
backend.formatter = Lucky::PrettyLogFormatter.proc | ||
Log.dexter.configure(:debug, backend) | ||
DB::Log.level = :info | ||
end | ||
|
||
# Lucky only logs when before/after pipes halt by redirecting, or rendering a | ||
# response. Pipes that run without halting are not logged. | ||
# | ||
# If you want to log every pipe that runs, set the log level to ':info' | ||
Lucky::ContinuedPipeLog.dexter.configure(:none) | ||
|
||
# Lucky only logs failed queries by default. | ||
# | ||
# Set the log to ':info' to log all queries | ||
Avram::QueryLog.dexter.configure(:none) | ||
|
||
# Subscribe to Pulsar events to log when queries are made, | ||
# queries fail, or save operations fail. Remove this to | ||
# disable these log events without disabling all logging. | ||
Avram.initialize_logging | ||
|
||
# Skip logging static assets requests in development | ||
Lucky::LogHandler.configure do |settings| | ||
if LuckyEnv.development? | ||
settings.skip_if = ->(context : HTTP::Server::Context) { | ||
context.request.method.downcase == "get" && | ||
context.request.resource.starts_with?(/\/css\/|\/js\/|\/assets\/|\/favicon\.ico/) | ||
} | ||
end | ||
end |
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,10 @@ | ||
# This is used when generating URLs for your application | ||
Lucky::RouteHelper.configure do |settings| | ||
if LuckyEnv.production? | ||
# Example: https://my_app.com | ||
settings.base_uri = ENV.fetch("APP_DOMAIN") | ||
else | ||
# Set domain to the default host/port in development/test | ||
settings.base_uri = "http://localhost:#{Lucky::ServerSettings.port}" | ||
end | ||
end |
Oops, something went wrong.