-
-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Kamal deployment #1192
base: master
Are you sure you want to change the base?
[WIP] Kamal deployment #1192
Changes from 5 commits
f8b6f48
bcd0f87
fbb3502
e6bdeb0
af50d5f
328ccae
60fca18
db6cdfd
04a1c4c
a75bd59
2ec6d2a
e04c8b5
efbd6cc
e124196
b974128
8b3c713
c35d27f
5852120
2604d33
52240c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
to: "config/deploy.yml" | ||
skip_exists: true | ||
message: "Deploy file generated successfully." | ||
--- | ||
|
||
# Name of your application. Used to uniquely configure containers. | ||
service: {{pkg_name}} | ||
|
||
# Name of the container image. | ||
image: docker_username/{{pkg_name}} | ||
|
||
# Deploy to these servers. | ||
servers: | ||
web: | ||
- server_ip_address | ||
# job: | ||
# hosts: | ||
# - 192.168.0.1 | ||
# cmd: bin/jobs | ||
|
||
# Enable SSL auto certification via Let's Encrypt and allow for multiple apps on a single web server. | ||
# Remove this section when using multiple web servers and ensure you terminate SSL at your load balancer. | ||
# | ||
# Note: If using Cloudflare, set encryption mode in SSL/TLS setting to "Full" to enable CF-to-app encryption. | ||
proxy: | ||
ssl: true | ||
host: domain_name | ||
# Proxy connects to your container on port 80 by default. | ||
app_port: 5150 | ||
healthcheck: | ||
interval: 3 | ||
path: /_health | ||
timeout: 3 | ||
|
||
# Credentials for your image host. | ||
registry: | ||
# Specify the registry server, if you're not using Docker Hub | ||
# server: registry.digitalocean.com / ghcr.io / ... | ||
username: docker_username | ||
|
||
# Always use an access token rather than real password (pulled from .kamal/secrets). | ||
password: | ||
- KAMAL_REGISTRY_PASSWORD | ||
|
||
# Configure builder setup. | ||
builder: | ||
arch: amd64 | ||
# Pass in additional build args needed for your Dockerfile. | ||
# args: | ||
|
||
# Inject ENV variables into containers (secrets come from .kamal/secrets). | ||
# | ||
# env: | ||
# clear: | ||
# DB_HOST: 192.168.0.2 | ||
# secret: | ||
# - RAILS_MASTER_KEY | ||
{% if postgres or background_queue %} | ||
env: | ||
clear: | ||
{% endif -%} | ||
{%- if background_queue %} | ||
REDIS_URL: "redis://{{pkg_name}}-redis" | ||
{%- endif %} | ||
{%- if postgres %} | ||
secret: | ||
- DATABASE_URL | ||
- POSTGRES_PASSWORD | ||
{%- endif %} | ||
|
||
# Aliases are triggered with "bin/kamal <alias>". You can overwrite arguments on invocation: | ||
# "bin/kamal logs -r job" will tail logs from the first server in the job section. | ||
# | ||
# aliases: | ||
# shell: app exec --interactive --reuse "bash" | ||
|
||
# Use a different ssh user than root | ||
# | ||
# ssh: | ||
# user: app | ||
|
||
# Use a persistent storage volume. | ||
# | ||
# volumes: | ||
# - "app_storage:/app/storage" | ||
{% if sqlite -%} | ||
# Use a persistent database volume. | ||
volumes: | ||
# /var/lib/docker/volumes/data/_data | ||
- "data:/usr/app" | ||
{% endif -%} | ||
|
||
|
||
# Bridge fingerprinted assets, like JS and CSS, between versions to avoid | ||
# hitting 404 on in-flight requests. Combines all files from new and old | ||
# version inside the asset_path. | ||
# | ||
# asset_path: /app/public/assets | ||
|
||
# Configure rolling deploys by setting a wait time between batches of restarts. | ||
# | ||
# boot: | ||
# limit: 10 # Can also specify as a percentage of total hosts, such as "25%" | ||
# wait: 2 | ||
|
||
# Use accessory services (secrets come from .kamal/secrets). | ||
# | ||
# accessories: | ||
# db: | ||
# image: mysql:8.0 | ||
# host: 192.168.0.2 | ||
# port: 3306 | ||
# env: | ||
# clear: | ||
# MYSQL_ROOT_HOST: '%' | ||
# secret: | ||
# - MYSQL_ROOT_PASSWORD | ||
# files: | ||
# - config/mysql/production.cnf:/etc/mysql/my.cnf | ||
# - db/production.sql:/docker-entrypoint-initdb.d/setup.sql | ||
# directories: | ||
# - data:/var/lib/mysql | ||
# redis: | ||
# image: valkey/valkey:8 | ||
# host: 192.168.0.2 | ||
# port: 6379 | ||
# directories: | ||
# - data:/data | ||
|
||
{% if postgres or background_queue %} | ||
accessories: | ||
{% endif -%} | ||
{%- if postgres %} | ||
db: | ||
image: postgres:16 | ||
host: server_ip_address | ||
port: "127.0.0.1:5432:5432" | ||
env: | ||
clear: | ||
POSTGRES_USER: loco | ||
POSTGRES_DB: {{pkg_name}}_production | ||
secret: | ||
- POSTGRES_PASSWORD | ||
directories: | ||
- data:/var/lib/postgresql/data | ||
{% endif %} | ||
{%- if background_queue %} | ||
redis: | ||
image: valkey/valkey:8 | ||
host: server_ip_address | ||
port: "127.0.0.1:6379:6379" | ||
directories: | ||
- data:/data | ||
{% endif %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
to: "Dockerfile" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we not using the same docker template that we already have? I don't think we need to hold two docker templates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current docker template has a different purpose than the one kamal one. As I can see the current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question is, why should SeaORM be included in this docker file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My current dockerfile for kamal setup is serving the server within the container instead of just compiling, which requires database connection like sqlite or postgres. Therefore SeaOrm is kinda required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait sea orm cli is not required for database connection? Okay I will remove it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check if you can use the current docker file and not create a new one |
||
skip_exists: true | ||
message: "Dockerfile generated successfully." | ||
|
||
injections: | ||
- into: config/development.yaml | ||
after: " port: 5150" | ||
content: " # Expose Server on all interfaces\n binding: 0.0.0.0" | ||
|
||
--- | ||
|
||
FROM rust:1.84-slim as builder | ||
|
||
WORKDIR /usr/src/ | ||
|
||
COPY . . | ||
|
||
RUN cargo build --release | ||
|
||
FROM debian:bookworm-slim | ||
# Install required system dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
pkg-config \ | ||
libpq-dev \ | ||
libssl-dev \ | ||
curl \ | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Rust | ||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
||
# Install sea-orm-cli | ||
RUN cargo install sea-orm-cli | ||
WORKDIR /usr/app | ||
{% if copy_asset_folder -%} | ||
COPY --from=builder /usr/src/{{copy_asset_folder}} /usr/app/{{copy_asset_folder}} | ||
{% endif -%} | ||
COPY --from=builder /usr/src/assets/views /usr/app/assets/views | ||
{% if fallback_file -%} | ||
COPY --from=builder /usr/src/{{fallback_file}} /usr/app/{{fallback_file}} | ||
{% endif -%} | ||
COPY --from=builder /usr/src/config /usr/app/config | ||
COPY --from=builder /usr/src/target/release/{{pkg_name}}-cli /usr/app/{{pkg_name}}-cli | ||
|
||
ENTRYPOINT ["/usr/app/{{pkg_name}}-cli","start"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
to: ".kamal/secrets" | ||
skip_exists: true | ||
message: "Secrets file generated successfully." | ||
--- | ||
# Secrets defined here are available for reference under registry/password, env/secret, builder/secrets, | ||
# and accessories/*/env/secret in config/deploy.yml. All secrets should be pulled from either | ||
# password manager, ENV, or a file. DO NOT ENTER RAW CREDENTIALS HERE! This file needs to be safe for git. | ||
|
||
# Option 1: Read secrets from the environment | ||
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD | ||
{% if postgres -%} | ||
# example: export POSTGRES_PASSWORD="loco" | ||
POSTGRES_PASSWORD=$POSTGRES_PASSWORD | ||
# example: export DATABASE_URL="postgresql://loco:$POSTGRES_PASSWORD@{{pkg_name}}-db:5432/{{pkg_name}}_production" | ||
DATABASE_URL=$DATABASE_URL | ||
{% endif %} | ||
# Option 2: Read secrets via a command | ||
# RAILS_MASTER_KEY=$(cat config/master.key) | ||
|
||
# Option 3: Read secrets via kamal secrets helpers | ||
# These will handle logging in and fetching the secrets in as few calls as possible | ||
# There are adapters for 1Password, LastPass + Bitwarden | ||
# | ||
# SECRETS=$(kamal secrets fetch --adapter 1password --account my-account --from MyVault/MyItem KAMAL_REGISTRY_PASSWORD RAILS_MASTER_KEY) | ||
# KAMAL_REGISTRY_PASSWORD=$(kamal secrets extract KAMAL_REGISTRY_PASSWORD $SECRETS) | ||
# RAILS_MASTER_KEY=$(kamal secrets extract RAILS_MASTER_KEY $SECRETS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that none of the parameters (
fallback_file
,asset_folder
,host
,port
) and also the new params are strictly necessary.The deployment function should take a reference to &Config (you already have the config in
cli.rs
), and each deployment type should be able to utilize the configuration that works best for it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaplanelad I was trying to use &loco-rs::config::Config in loco gen project. However, importing loco-rs within loco-gen will cause cyclic dependency