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
```
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
Feel free to make pull requests!

View File

@ -1,5 +1,6 @@
host: example.com
host: 0.0.0.0
port: 80
site_url: 0x45.st
database_url: postgres://postgres@127.0.0.1/paste69
storage:
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:
github: straight-shoota/crinja
crecto:
# github: Crecto/crecto
# branch: master
path: ../crecto
github: Crecto/crecto
branch: master
pg:
github: will/crystal-pg
version: ~> 0.23.2

View File

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

View File

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