From d163711d2bbf04701ce242eb60bb572e3b6c22ec Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Tue, 3 Oct 2023 19:40:23 +0200 Subject: [PATCH 1/4] Remove monkeypatch since the commit has been merged since v1.0.4 See https://github.com/postrank-labs/goliath/commit/79d43b80c9c1345034c6f40a60b1be064e493af3 --- lib/board-linuxfr.rb | 1 - lib/board-linuxfr/monkeypatch.rb | 48 -------------------------------- 2 files changed, 49 deletions(-) delete mode 100644 lib/board-linuxfr/monkeypatch.rb diff --git a/lib/board-linuxfr.rb b/lib/board-linuxfr.rb index 12b0143..6bb1230 100644 --- a/lib/board-linuxfr.rb +++ b/lib/board-linuxfr.rb @@ -1,5 +1,4 @@ require "goliath" -require "board-linuxfr/monkeypatch" require "yajl" diff --git a/lib/board-linuxfr/monkeypatch.rb b/lib/board-linuxfr/monkeypatch.rb deleted file mode 100644 index e9af0f9..0000000 --- a/lib/board-linuxfr/monkeypatch.rb +++ /dev/null @@ -1,48 +0,0 @@ -# Monkeypatch Goliath to avoid it to crash on invalid parser. -# It's the backport of a commit, waiting for a release. This commit: -# https://github.com/postrank-labs/goliath/commit/79d43b80c9c1345034c6f40a60b1be064e493af3 - -class Goliath::Request - - # Invoked by connection when header parsing is complete. - # This method is invoked only once per request. - # - # @param h [Hash] Request headers - # @param parser [Http::Parser] The parser used to parse the request - # @return [Nil] - def parse_header(h, parser) - h.each do |k, v| - @env[HTTP_PREFIX + k.gsub('-','_').upcase] = v - end - - %w(CONTENT_TYPE CONTENT_LENGTH).each do |name| - @env[name] = @env.delete("HTTP_#{name}") if @env["HTTP_#{name}"] - end - - if @env['HTTP_HOST'] - name, port = @env['HTTP_HOST'].split(':') - @env[SERVER_NAME] = name if name - @env[SERVER_PORT] = port if port - end - - begin - uri = URI(parser.request_url) - - @env[REQUEST_METHOD] = parser.http_method - @env[REQUEST_URI] = parser.request_url - @env[QUERY_STRING] = uri.query - @env[HTTP_VERSION] = parser.http_version.join('.') - @env[SCRIPT_NAME] = uri.path - @env[REQUEST_PATH] = uri.path - @env[PATH_INFO] = uri.path - @env[FRAGMENT] = uri.fragment - - yield if block_given? - - @env[ASYNC_HEADERS].call(@env, h) if @env[ASYNC_HEADERS] - rescue Exception => e - server_exception(e) - end - end - -end From 9ce1a95ef3df6b2cab0c1335d1efec4d2d781147 Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Mon, 9 Oct 2023 21:14:26 +0200 Subject: [PATCH 2/4] Add Dockerfile and update gemspec definition --- .dockerignore | 3 +++ board-linuxfr.gemspec | 14 +++++++------- deployment/Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ deployment/default.env | 3 +++ docker-compose.yaml | 18 ++++++++++++++++++ lib/board-linuxfr/version.rb | 2 +- 6 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 deployment/Dockerfile create mode 100644 deployment/default.env create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..58b45bf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/.git +/deployment +.*.swp diff --git a/board-linuxfr.gemspec b/board-linuxfr.gemspec index 4f05bd2..880e245 100644 --- a/board-linuxfr.gemspec +++ b/board-linuxfr.gemspec @@ -6,21 +6,21 @@ require './lib/board-linuxfr/version' Gem::Specification.new do |s| s.name = "board-linuxfr" s.version = BoardLinuxfr::VERSION - s.authors = ["Bruno Michel"] - s.email = "nono@linuxfr.org" + s.authors = ["Bruno Michel", "Adrien Dorsaz"] + s.email = "adrien@adorsaz.ch" s.homepage = "https://github.com/linuxfrorg/board-sse-linuxfr.org" s.summary = "Push notifications for the board of LinuxFr.org via Server-Sent Events" s.description = "Push notifications for the board of LinuxFr.org via Server-Sent Events" - s.files = `git ls-files bin lib`.split("\n") + s.files = Dir['lib/**/*.rb'] + Dir['bin/*'] s.platform = Gem::Platform::RUBY s.executables = ["board-linuxfr"] s.require_path = 'lib' - s.add_dependency "goliath", "~>1.0" - s.add_dependency "hiredis", "~>0.4" - s.add_dependency "redis", "~>3.0" - s.add_dependency "yajl-ruby", "~>1.2" + s.add_runtime_dependency "goliath", "~>1.0", ">= 1.0.7" + s.add_runtime_dependency "hiredis", "~>0.4" + s.add_runtime_dependency "redis", "~>3.0" + s.add_runtime_dependency "yajl-ruby", "~>1.2" s.add_development_dependency "minitest", "~>2.3" end diff --git a/deployment/Dockerfile b/deployment/Dockerfile new file mode 100644 index 0000000..2a5eb04 --- /dev/null +++ b/deployment/Dockerfile @@ -0,0 +1,36 @@ +FROM ruby:3-slim-bookworm + +LABEL org.opencontainers.image.title="LinuxFr.org boards" +LABEL org.opencontainers.image.description="Chat rooms for LinuxFr" +LABEL org.opencontainers.image.source="https://github.com/linuxfrorg/board-sse-linuxfr.org" +LABEL org.opencontainers.image.url="https://github.com/linuxfrorg/board-sse-linuxfr.org" +LABEL org.opencontainers.image.licenses="AGPL-3.0-only" +LABEL org.opencontainers.image.version="ruby3-bookworm" +LABEL org.opencontainers.image.authors="Adrien Dorsaz " + +ARG UID=1200 + +RUN apt-get update \ + # Install dependencies \ + && apt-get install -y --no-install-recommends \ + build-essential ruby ruby-dev \ + && apt-get clean + +USER ${UID} +WORKDIR /linuxfr-board +ENV HOME=/linuxfr-board + +# Install board-linuxfr +COPY --chown=${UID}:0 --chmod=770 . . +RUN gem build board-linuxfr.gemspec \ + && gem install ./board-linuxfr-*.gem + +# Clean development dependencies +USER 0 +RUN apt purge --autoremove -y build-essential ruby-dev + +USER ${UID} +EXPOSE 9000 + +CMD ["board-linuxfr"] + diff --git a/deployment/default.env b/deployment/default.env new file mode 100644 index 0000000..93530d1 --- /dev/null +++ b/deployment/default.env @@ -0,0 +1,3 @@ +REDIS_HOST=redis +REDIS_PORT=6379 +REDIS_URL=redis://redis:6379/0 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f2ad2a0 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,18 @@ +services: + linuxfr-board: + build: + context: . + dockerfile: ./deployment/Dockerfile + env_file: + - deployment/default.env + depends_on: + - redis + + redis: + image: redis:5 + volumes: + - data-redis:/data + +volumes: + data-redis: + driver: local diff --git a/lib/board-linuxfr/version.rb b/lib/board-linuxfr/version.rb index e2bab99..25e7ea3 100644 --- a/lib/board-linuxfr/version.rb +++ b/lib/board-linuxfr/version.rb @@ -1,3 +1,3 @@ class BoardLinuxfr - VERSION = "0.1.3" + VERSION = "0.1.4" end From 018ef4c320d2ac641ed7af3e4c882501f80a3671 Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Fri, 8 Mar 2024 15:32:52 +0100 Subject: [PATCH 3/4] rename container file and compose file to the new convention This is more accurate because developper can use Docker or Podman to build container image --- docker-compose.yaml => compose.yaml | 2 +- deployment/{Dockerfile => Containerfile} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename docker-compose.yaml => compose.yaml (84%) rename deployment/{Dockerfile => Containerfile} (100%) diff --git a/docker-compose.yaml b/compose.yaml similarity index 84% rename from docker-compose.yaml rename to compose.yaml index f2ad2a0..08cde7b 100644 --- a/docker-compose.yaml +++ b/compose.yaml @@ -2,7 +2,7 @@ services: linuxfr-board: build: context: . - dockerfile: ./deployment/Dockerfile + dockerfile: ./deployment/Containerfile env_file: - deployment/default.env depends_on: diff --git a/deployment/Dockerfile b/deployment/Containerfile similarity index 100% rename from deployment/Dockerfile rename to deployment/Containerfile From a1ab5aef56824642e2b411ba97bedab64555ba4c Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Fri, 8 Mar 2024 23:13:20 +0100 Subject: [PATCH 4/4] add github workflows to build a container and to publish the gem --- .dockerignore | 1 + .github/workflows/build.yaml | 25 ++++++++++++++++++ .github/workflows/release.yaml | 47 ++++++++++++++++++++++++++++++++++ deployment/Containerfile | 25 ++++++++++++------ 4 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.dockerignore b/.dockerignore index 58b45bf..6f3eb16 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ /.git +/.github /deployment .*.swp diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..1edaf72 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,25 @@ +name: Build the ruby gem in a container +on: + pull_request: + +jobs: + build-ruby-gem: + runs-on: ubuntu-latest + steps: + - name: Checkout project code + uses: actions/checkout@v4 + + - name: Setup Docker builder + uses: docker/setup-buildx-action@v3 + + - name: Build container for build target + uses: docker/build-push-action@v5 + with: + context: . + file: ./deployment/Containerfile + target: build + push: false + load: true + tags: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..f19c194 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,47 @@ +name: Build the ruby gem in a container and publish it on Github Package Repository +on: + release: + types: + - published + +jobs: + build-ruby-gem: + runs-on: ubuntu-latest + steps: + - name: Checkout project code + uses: actions/checkout@v4 + + - name: Setup Docker builder + uses: docker/setup-buildx-action@v3 + + - name: Build container for build target + uses: docker/build-push-action@v5 + with: + context: . + file: ./deployment/Containerfile + target: build + push: false + load: true + tags: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Publish gem to Github Package Repository + uses: addnab/docker-run-action@v3 + env: + GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}" + OWNER: ${{ github.repository_owner }} + with: + image: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }} + options: >- + -e OWNER + -e GEM_HOST_API_KEY + run: | + set -eux + IFS=$'\n\t' + + mkdir -p "${HOME}/.gem" + touch "${HOME}/.gem/credentials" + chmod 0600 "${HOME}/.gem/credentials" + printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > "${HOME}/.gem/credentials" + gem push --KEY github --host "https://rubygems.pkg.github.com/${OWNER}" *.gem diff --git a/deployment/Containerfile b/deployment/Containerfile index 2a5eb04..58720da 100644 --- a/deployment/Containerfile +++ b/deployment/Containerfile @@ -1,4 +1,4 @@ -FROM ruby:3-slim-bookworm +FROM ruby:3-slim-bookworm AS build LABEL org.opencontainers.image.title="LinuxFr.org boards" LABEL org.opencontainers.image.description="Chat rooms for LinuxFr" @@ -10,11 +10,17 @@ LABEL org.opencontainers.image.authors="Adrien Dorsaz " ARG UID=1200 -RUN apt-get update \ - # Install dependencies \ - && apt-get install -y --no-install-recommends \ - build-essential ruby ruby-dev \ - && apt-get clean +RUN <