diff --git a/Dockerfile b/Dockerfile index e3fb7da..47d47b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ COPY src/ src/ COPY runtimes/ runtimes/ RUN shards install RUN shards build -d --error-trace +RUN cat .rucksack >> bin/faaso # RUN strip bin/* FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship @@ -16,6 +17,8 @@ RUN apk update && apk add caddy nss-tools multirun docker openssl zlib yaml pcre # Unprivileged user RUN addgroup -S app && adduser app -S -G app WORKDIR /home/app +RUN mkdir /home/app/tmp && chown app /home/app/tmp + RUN mkdir runtimes public COPY public/ public/ diff --git a/Makefile b/Makefile index 9b4f600..a80e737 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ build: shard.yml $(wildcard src/**/*) $(runtimes/**/*) proxy: build docker build . -t faaso-proxy start-proxy: - docker run --name faaso-proxy-one --rm --network=faaso-net --env-file=proxy.env -v /var/run/docker.sock:/var/run/docker.sock -v secrets:/home/app/secrets -p 8888:8888 faaso-proxy + docker run --name faaso-proxy-one --rm --network=faaso-net --env-file=proxy.env -e FAASO_SECRET_PATH=${PWD}/secrets -v /var/run/docker.sock:/var/run/docker.sock -v secrets:/home/app/secrets -p 8888:8888 faaso-proxy .PHONY: build proxy-image start-proxy diff --git a/src/funko.cr b/src/funko.cr index 1358cdc..8de06a9 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -80,12 +80,7 @@ module Funko # Get the number of running instances of this funko def scale - docker_api = Docr::API.new(Docr::Client.new) - docker_api.containers.list.select { |container| - container.@state == "running" - }.count { |container| - container.@names.any?(&.starts_with?("/faaso-#{name}-")) - } + containers.size end # Set the number of running instances of this funko @@ -153,9 +148,12 @@ module Funko def build(path : Path) Log.info { "Building image for #{name} in #{path}" } docker_api = Docr::API.new(Docr::Client.new) + tags = ["faaso-#{name}:latest"] + Log.info { " Tags: #{tags}" } docker_api.images.build( context: path.to_s, - tags: ["faaso-#{name}:latest"]) { |x| Log.info { x } } + tags: tags, + no_cache: true) { |x| Log.info { x } } end def images @@ -232,7 +230,15 @@ module Funko # Create a container for this funko def create_container(autostart : Bool = true) : String - secrets_mount = "#{Dir.current}/secrets/#{name}" + # The path to secrets is tricky. On the server it will be in + # ./secrets/ BUT when you call on the Docker API you need to + # pass the path in the HOST SYSTEM WHERE DOCKER IS RUNNING + # so allow for a FAASO_SECRET_PATH override which will + # be set for the proxy container + secrets_mount = ENV.fetch( + "FAASO_SECRET_PATH", + "#{Dir.current}/secrets/#{name}" + ) Dir.mkdir_p(secrets_mount) conf = Docr::Types::CreateContainerConfig.new( image: "faaso-#{name}:latest",