docker support

This commit is contained in:
Chris W 2024-01-02 20:09:05 -07:00
parent c150387c16
commit e35c7a7085
7 changed files with 40 additions and 23 deletions

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM crystallang/crystal:latest
WORKDIR /app
RUN apt-get update && apt-get install libmagic-dev -y
COPY . .
RUN shards install
RUN shards build --release
ENTRYPOINT [ "docker/entrypoint.sh" ]

View File

@ -30,6 +30,12 @@ shards build
./bin/server ./bin/server
``` ```
Alternatively, you can use Docker to make things quicker:
```bash
docker build -v ./uploads:/app/uploads --tag paste69 ./docker
docker run -d -p 8080:8080 paste69
```
## Development ## Development
Feel free to make pull requests! Feel free to make pull requests!

View File

@ -1,5 +1,6 @@
host: example.com host: 0.0.0.0
port: 80 port: 80
site_url: 0x45.st
database_url: postgres://postgres@127.0.0.1/paste69 database_url: postgres://postgres@127.0.0.1/paste69
storage: storage:
type: local type: local

6
docker/entrypoint.sh Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
bin/cli db:create > /dev/null 2>&1
bin/cli db:migrate > /dev/null 2>&1
bin/server

View File

@ -17,9 +17,8 @@ dependencies:
crinja: crinja:
github: straight-shoota/crinja github: straight-shoota/crinja
crecto: crecto:
# github: Crecto/crecto github: Crecto/crecto
# branch: master branch: master
path: ../crecto
pg: pg:
github: will/crystal-pg github: will/crystal-pg
version: ~> 0.23.2 version: ~> 0.23.2

View File

@ -4,8 +4,10 @@ module Paste69
getter config : Totem::Config getter config : Totem::Config
DEFAULTS = { DEFAULTS = {
"host" => nil, "host" => "0.0.0.0",
"port" => 8080, "port" => 8080,
"site_url" => "0.0.0.0:8080",
"use_ssl" => false,
"database_url" => "sqlite://./db/data.db", "database_url" => "sqlite://./db/data.db",
"templates_dir" => "src/templates", "templates_dir" => "src/templates",
"max_content_length" => 256 * 1024 * 1024, "max_content_length" => 256 * 1024 * 1024,
@ -56,16 +58,13 @@ module Paste69
def initialize def initialize
config = @config = Totem.new("config", "/etc/paste69") config = @config = Totem.new("config", "/etc/paste69")
config.config_paths << "~/.totem" config.config_paths << "~/.paste69"
config.config_paths << "~/.config/totem" config.config_paths << "~/.config/paste69"
config.config_paths << "./config" config.config_paths << "./config"
begin
config.load! config.load! rescue nil
config.set_defaults(DEFAULTS) config.automatic_env
rescue ex config.set_defaults(DEFAULTS)
puts "Fatal error loading config file: #{ex.message}"
exit(1)
end
end end
end end
end end

View File

@ -4,19 +4,13 @@ module Paste69
def initialize(@config : Paste69::ConfigManager, @type_checker : Paste69::TypeChecker); end def initialize(@config : Paste69::ConfigManager, @type_checker : Paste69::TypeChecker); end
def url_for(name, *, secret : String? = nil, anchor : String? = nil) def url_for(name, *, secret : String? = nil, anchor : String? = nil)
host = @config.get("host").as_s url = @config.get("site_url").as_s
port = @config.get("port").as_i ssl = @config.get("use_ssl").as_bool
url = host
if port != 80 && port!= 443
url += ":#{port}"
end
url = secret ? File.join(url, secret, name) : File.join(url, name) url = secret ? File.join(url, secret, name) : File.join(url, name)
url += "##{anchor}" if anchor url += "##{anchor}" if anchor
scheme = port == 443 ? "https" : "http" scheme = ssl ? "https" : "http"
"#{scheme}://#{url}" "#{scheme}://#{url}"
end end