Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions fixtures/src_template/expected/docker/development.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ FROM crystallang/crystal:1.16.1
RUN apt-get update && \
apt-get install -y wget

# Apt installs:
# - Postgres cli tools are required for lucky-cli.
# - tmux is required for the Overmind process manager.
RUN apt-get update && \
apt-get install -y postgresql-client tmux && \
rm -rf /var/lib/apt/lists/*

# Install lucky cli
WORKDIR /lucky/cli
RUN git clone https://github.com/luckyframework/lucky_cli . && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ FROM crystallang/crystal:1.16.1
RUN apt-get update && \
apt-get install -y wget

# Apt installs:
# - Postgres cli tools are required for lucky-cli.
# - tmux is required for the Overmind process manager.
RUN apt-get update && \
apt-get install -y postgresql-client tmux && \
rm -rf /var/lib/apt/lists/*

# Install lucky cli
WORKDIR /lucky/cli
RUN git clone https://github.com/luckyframework/lucky_cli . && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ if ! [ -d bin ] ; then
echo 'Creating bin directory'
mkdir bin
fi
echo 'Installing npm packages...'

echo 'Installing yarn packages...'
yarn install

if ! shards check ; then
echo 'Installing shards...'
shards install
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.16.1
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: test-project CI

on:
push:
branches: "*"
pull_request:
branches: "*"

jobs:
check-format:
strategy:
fail-fast: false
matrix:
crystal_version:
- 1.16.1
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.16.1
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: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Set up Yarn cache
uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Set up Node cache
uses: actions/cache@v4
id: node-cache # use this to check for `cache-hit` (`steps.node-cache.outputs.cache-hit != 'true'`)
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- 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: Install yarn packages
if: steps.node-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --no-progress
- name: Compiling assets
run: yarn prod
- 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 -Dwith_sec_tests
2 changes: 2 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: bin/app
release: lucky db.migrate
3 changes: 3 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
system_check: crystal script/system_check.cr
web: lucky watch --reload-browser
assets: yarn watch
23 changes: 23 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# test-project

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).
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 = "[email protected]"
# settings.lock_with_basic_auth = LuckyEnv.staging?
# end
#
# # In your application, call
# # `Application.settings.support_email` anywhere you need it.
# ```
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?
25 changes: 25 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/config/cookies.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "./server"

Lucky::Session.configure do |settings|
settings.key = "_test_project_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
29 changes: 29 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/config/database.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
database_name = "test_project_#{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
26 changes: 26 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/config/email.cr
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
33 changes: 33 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/config/env.cr
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
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
50 changes: 50 additions & 0 deletions fixtures/src_template__js_bun_bundler/expected/config/log.cr
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
Loading
Loading