Compare commits

...

4 Commits

Author SHA1 Message Date
81ec077928 Use base58 2024-07-08 22:34:38 -03:00
afb6e8df0c Dockerfile linter 2024-07-08 22:34:27 -03:00
50e8ff7e56 add check to ensure config/funkos is empty 2024-07-08 22:34:07 -03:00
6489ec0dc2 Use base58 for random strings 2024-07-08 22:33:52 -03:00
8 changed files with 47 additions and 14 deletions

3
.hadolint.yml Normal file
View File

@ -0,0 +1,3 @@
ignored:
- DL3018
- DL3059

View File

@ -31,3 +31,8 @@ repos:
entry: test ! -s config/funkos entry: test ! -s config/funkos
language: system language: system
pass_filenames: false pass_filenames: false
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint-docker
exclude: 'j2$'

View File

@ -1,5 +1,13 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as build FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.20 AS build
RUN apk update && apk add crystal shards yaml-dev openssl-dev zlib-dev libxml2-dev make && apk cache clean RUN apk add --no-cache \
crystal \
shards \
yaml-dev \
openssl-dev \
zlib-dev \
libxml2-dev \
make
RUN rm -rf /var/cache/apk/*
RUN addgroup -S app && adduser app -S -G app RUN addgroup -S app && adduser app -S -G app
WORKDIR /home/app WORKDIR /home/app
COPY shard.yml Makefile ./ COPY shard.yml Makefile ./
@ -9,8 +17,22 @@ COPY runtimes/ runtimes/
RUN make RUN make
# RUN strip bin/* # RUN strip bin/*
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.20 AS ship
RUN apk update && apk add caddy nss-tools multirun docker openssl zlib yaml pcre2 gc libevent libgcc libxml2 ttyd && apk cache clean RUN apk add --no-cache \
caddy \
nss-tools \
multirun \
docker \
openssl \
zlib \
yaml \
pcre2 \
gc \
libevent \
libgcc \
libxml2 \
ttyd
RUN rm -rf /var/cache/apk/*
# Unprivileged user # Unprivileged user
RUN addgroup -S app && adduser app -S -G app RUN addgroup -S app && adduser app -S -G app
@ -21,7 +43,6 @@ COPY public/ public/
COPY --from=build /home/app/bin/faaso-daemon /home/app/bin/faaso /usr/bin/ COPY --from=build /home/app/bin/faaso-daemon /home/app/bin/faaso /usr/bin/
# Mount points for persistent data # Mount points for persistent data
RUN mkdir /secrets RUN mkdir /secrets /config
RUN mkdir /config
CMD ["/usr/bin/multirun", "-v", "faaso-daemon", "caddy run --config config/Caddyfile"] CMD ["/usr/bin/multirun", "-v", "faaso-daemon", "caddy run --config config/Caddyfile"]

View File

@ -4,6 +4,10 @@ shards:
git: https://github.com/sija/backtracer.cr.git git: https://github.com/sija/backtracer.cr.git
version: 1.2.2 version: 1.2.2
base58:
git: https://github.com/crystal-china/base58.cr.git
version: 0.1.0+git.commit.d1150d4a6f086013a475640ad00e561a2fe1082a
cr-config: cr-config:
git: https://github.com/crystal-community/cr-config.git git: https://github.com/crystal-community/cr-config.git
version: 5.1.0+git.commit.5eae3dfbf97da7dfa7c6e64a2a508069948518d3 version: 5.1.0+git.commit.5eae3dfbf97da7dfa7c6e64a2a508069948518d3

View File

@ -15,6 +15,8 @@ crystal: ">= 1.12.2"
license: MIT license: MIT
dependencies: dependencies:
base58:
github: crystal-china/base58.cr
crest: crest:
github: mamantoha/crest github: mamantoha/crest
crinja: crinja:

View File

@ -1,3 +1,5 @@
require "base58"
module Faaso module Faaso
module Commands module Commands
# Build images for one or more funkos from source # Build images for one or more funkos from source
@ -7,7 +9,7 @@ module Faaso
# Create temporary build location # Create temporary build location
funkos.each do |funko| funkos.each do |funko|
tmp_dir = Path.new("tmp", UUID.random.to_s) tmp_dir = Path.new("tmp", Random.base58(8))
Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir
funko.runtime = nil if options["--no-runtime"] funko.runtime = nil if options["--no-runtime"]

View File

@ -1,3 +1,4 @@
require "base58"
require "docr" require "docr"
require "kemal" require "kemal"
require "../funko.cr" require "../funko.cr"
@ -34,7 +35,7 @@ module Funko
# mosquito-cr/mosquito to make it a job queue # mosquito-cr/mosquito to make it a job queue
post "/funkos/build/" do |env| post "/funkos/build/" do |env|
# Create place to build funko # Create place to build funko
tmp_dir = Path.new("tmp", UUID.random.to_s) tmp_dir = Path.new("tmp", Random.base58(8))
Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir
# Expand tarball in there # Expand tarball in there

View File

@ -309,7 +309,7 @@ module Funko
) )
docker_api = Docr::API.new(Docr::Client.new) docker_api = Docr::API.new(Docr::Client.new)
response = docker_api.containers.create(name: "faaso-#{name}-#{randstr}", config: conf) response = docker_api.containers.create(name: "faaso-#{name}-#{Random.base58(6)}", config: conf)
response.@warnings.each { |msg| Log.warn { msg } } response.@warnings.each { |msg| Log.warn { msg } }
docker_api.containers.start(response.@id) if autostart docker_api.containers.start(response.@id) if autostart
response.@id response.@id
@ -349,8 +349,3 @@ module Funko
end end
end end
end end
def randstr(length = 6) : String
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
String.new(Bytes.new(chars.to_slice.sample(length).to_unsafe, length))
end