From dfdb6b4020d44f794786711123fbb02b6b50fae3 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Thu, 16 Mar 2023 21:09:27 -0700 Subject: [PATCH 01/10] fun, image tagging, and SOURCE_TAG --- .woodpecker.yml | 43 +++++++++++++++++++++++++++++++++++------ Dockerfile | 6 ++++-- lib/mastodon/version.rb | 6 ++++-- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 651e9d7997..5f7bdcf11c 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,19 +1,50 @@ +variables: + image: &docker-git docker:rc-git + volumes: + - &docker.sock /var/run/docker.sock:/var/run/docker.sock + environment: + common: &common-env + NAME: gitea.treehouse.systems/treehouse/mastodon pipeline: build: - image: docker:rc-git + image: *docker-git volumes: - - /var/run/docker.sock:/var/run/docker.sock + - *docker.sock + environment: + <<: *common-env commands: - docker version - - docker image build -f Dockerfile . -t gitea.treehouse.systems/treehouse/mastodon:latest + - docker image build -f Dockerfile --build-arg SOURCE_TAG=$CI_COMMIT_SHA . -t $NAME:latest + - docker tag $NAME:latest $NAME:$CI_COMMIT_SHA + + tag-nightly: + image: *docker-git + volumes: + - *docker.sock + environment: + <<: *common-env + commands: + - docker tag $NAME:latest $NAME:$(date -Idate -u) + + # maybe we can use tags someday,,, + # tag-tag: + # image: *docker-git + # volumes: + # - /var/run/docker.sock:/var/run/docker.sock + # commands: + # - docker tag $NAME:latest $NAME:$CI_COMMIT_TAG + # when: + # event: tag push: - image: docker:rc-git + image: *docker-git volumes: - - /var/run/docker.sock:/var/run/docker.sock + - *docker.sock + environment: + <<: *common-env commands: - echo $REGISTRY_SECRET | docker login -u ariadne --password-stdin gitea.treehouse.systems - - docker image push --all-tags gitea.treehouse.systems/treehouse/mastodon + - docker image push --all-tags $NAME when: event: [push, tag] branch: main diff --git a/Dockerfile b/Dockerfile index 26a4b34f96..665a1bea46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1.4 # This needs to be bullseye-slim because the Ruby image is built on bullseye-slim -ARG NODE_VERSION="16.19-bullseye-slim" +ARG NODE_VERSION="18.15-bullseye-slim" FROM ghcr.io/moritzheiber/ruby-jemalloc:3.2.1-slim as ruby FROM node:${NODE_VERSION} as build @@ -59,6 +59,7 @@ RUN bundle exec rails assets:precompile FROM node:${NODE_VERSION} +ARG SOURCE_TAG='' ARG UID="991" ARG GID="991" @@ -102,7 +103,8 @@ COPY --link --chown=mastodon:mastodon --from=build /opt/mastodon /opt/mastodon ENV RAILS_ENV="production" \ NODE_ENV="production" \ RAILS_SERVE_STATIC_FILES="true" \ - BIND="0.0.0.0" + BIND="0.0.0.0" \ + SOURCE_TAG="${SOURCE_TAG}" # Set the run user USER mastodon diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index d25d1dd3f9..da07a398ec 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -21,7 +21,7 @@ module Mastodon end def suffix - '+glitch+th' + '+glitch.th' end def to_a @@ -42,7 +42,9 @@ module Mastodon # specify git tag or commit hash here def source_tag - ENV.fetch('SOURCE_TAG', nil) + tag = ENV.fetch('SOURCE_TAG', nil) + return if tag.nil? || tag.empty? + tag end def source_url From 73d37e9e665d62d6ea321897276f17bc03d0f7a8 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 18 Mar 2023 01:54:21 -0700 Subject: [PATCH 02/10] compose out of the box, more-or-less --- .env.production.sample | 9 +++++---- docker-compose.yml | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.env.production.sample b/.env.production.sample index 7bcce0f7e5..bd72ee0b41 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -14,7 +14,7 @@ # ---------- # This identifies your server and cannot be changed safely later # ---------- -LOCAL_DOMAIN=example.com +LOCAL_DOMAIN=localhost # Use this only if you need to run mastodon on a different domain than the one used for federation. # You can read more about this option on https://docs.joinmastodon.org/admin/config/#web-domain @@ -25,6 +25,7 @@ LOCAL_DOMAIN=example.com # handler@example2.com etc. for the same user. LOCAL_DOMAIN should not # be added. Comma separated values # ALTERNATE_DOMAINS=example1.com,example2.com +ALTERNATE_DOMAINS=mastodon.internal # Use HTTP proxy for outgoing request (optional) # http_proxy=http://gateway.local:8118 @@ -43,14 +44,14 @@ LOCAL_DOMAIN=example.com # Redis # ----- -REDIS_HOST=localhost +REDIS_HOST=redis REDIS_PORT=6379 # PostgreSQL # ---------- -DB_HOST=/var/run/postgresql -DB_USER=mastodon +DB_HOST=db +DB_USER=postgres DB_NAME=mastodon_production DB_PASS= DB_PORT=5432 diff --git a/docker-compose.yml b/docker-compose.yml index 9d0f7e4751..1991514424 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: healthcheck: test: ['CMD', 'pg_isready', '-U', 'postgres'] volumes: - - ./postgres14:/var/lib/postgresql/data + - ./data/postgres14:/var/lib/postgresql/data environment: - 'POSTGRES_HOST_AUTH_METHOD=trust' @@ -56,7 +56,7 @@ services: web: build: . - image: tootsuite/mastodon + image: gitea.treehouse.systems/treehouse/mastodon:latest restart: always env_file: .env.production command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000" @@ -82,10 +82,11 @@ services: # - es volumes: - ./public/system:/mastodon/public/system + - ./data/postgres14:/var/lib/postgresql/data streaming: build: . - image: tootsuite/mastodon + image: gitea.treehouse.systems/treehouse/mastodon:latest restart: always env_file: .env.production command: node ./streaming @@ -111,7 +112,7 @@ services: sidekiq: build: . - image: tootsuite/mastodon + image: gitea.treehouse.systems/treehouse/mastodon:latest restart: always env_file: .env.production command: bundle exec sidekiq From 093356a9af36c3f506fed31865c7eb24592c81e8 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Fri, 17 Mar 2023 22:54:32 -0700 Subject: [PATCH 03/10] ugh --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 752d202b15..09f6608e7b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -910,4 +910,4 @@ RUBY VERSION ruby 3.0.5p211 BUNDLED WITH - 2.3.26 + 2.4.6 From e52819c2fbc73ac605704e0554e7faa31cdaac99 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 18 Mar 2023 14:19:22 -0700 Subject: [PATCH 04/10] hack: fix excessively noisy babel traces --- package.json | 3 ++- yarn.lock | 19 ++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 4fabcaf2eb..99bd993833 100644 --- a/package.json +++ b/package.json @@ -165,7 +165,8 @@ "yargs": "^17.7.0" }, "resolutions": { - "kind-of": "^6.0.3" + "kind-of": "^6.0.3", + "@babel/types": "^7.21.3" }, "optionalDependencies": { "bufferutil": "^4.0.7", diff --git a/yarn.lock b/yarn.lock index 5a8176fb43..07864feb6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1505,25 +1505,14 @@ __metadata: languageName: node linkType: hard -"@babel/types@npm:^7.0.0, @babel/types@npm:^7.0.0-beta.49, @babel/types@npm:^7.18.10, @babel/types@npm:^7.18.6, @babel/types@npm:^7.18.9, @babel/types@npm:^7.19.0, @babel/types@npm:^7.20.0, @babel/types@npm:^7.20.2, @babel/types@npm:^7.20.7, @babel/types@npm:^7.21.0, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4": - version: 7.21.0 - resolution: "@babel/types@npm:7.21.0" +"@babel/types@npm:^7.21.3": + version: 7.21.3 + resolution: "@babel/types@npm:7.21.3" dependencies: "@babel/helper-string-parser": ^7.19.4 "@babel/helper-validator-identifier": ^7.19.1 to-fast-properties: ^2.0.0 - checksum: dbcdda202b3a2bfd59e4de880ce38652f1f8957893a9751be069ac86e47ad751222070fe6cd92220214d77973f1474e4e1111c16dc48199dfca1489c0ee8c0c5 - languageName: node - linkType: hard - -"@babel/types@npm:^7.8.3": - version: 7.21.2 - resolution: "@babel/types@npm:7.21.2" - dependencies: - "@babel/helper-string-parser": ^7.19.4 - "@babel/helper-validator-identifier": ^7.19.1 - to-fast-properties: ^2.0.0 - checksum: a45a52acde139e575502c6de42c994bdbe262bafcb92ae9381fb54cdf1a3672149086843fda655c7683ce9806e998fd002bbe878fa44984498d0fdc7935ce7ff + checksum: b750274718ba9cefd0b81836c464009bb6ba339fccce51b9baff497a0a2d96c044c61dc90cf203cec0adc770454b53a9681c3f7716883c802b85ab84c365ba35 languageName: node linkType: hard From ad81a51e37133fc4d4677c586d8f29557a841a06 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 18 Mar 2023 17:07:29 -0700 Subject: [PATCH 05/10] lol, broke the build --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 665a1bea46..6c07a60a3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ FROM node:${NODE_VERSION} as build COPY --link --from=ruby /opt/ruby /opt/ruby ENV DEBIAN_FRONTEND="noninteractive" \ - PATH="${PATH}:/opt/ruby/bin" + PATH="${PATH}:/opt/ruby/bin" \ + NODE_OPTIONS=--openssl-legacy-provider SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -50,11 +51,12 @@ ENV RAILS_ENV="production" \ # Precompile assets # TODO(kouhai): we're currently patching node_modules because of emoji-mart. # we should integrate our own fork instead. -COPY ./emoji_data/all.json ./node_modules/emoji-mart/data/all.json +COPY --link . /opt/mastodon ENV OTP_SECRET=precompile_placeholder \ SECRET_KEY_BASE=precompile_placeholder \ RAKE_NO_YARN_INSTALL_HACK=1 -RUN bundle exec rails assets:precompile +RUN mv ./emoji_data/all.json ./node_modules/emoji-mart/data/all.json && \ + bundle exec rails assets:precompile FROM node:${NODE_VERSION} @@ -97,7 +99,6 @@ RUN apt-get update && \ # Note: no, cleaning here since Debian does this automatically # See the file /etc/apt/apt.conf.d/docker-clean within the Docker image's filesystem -COPY --link --chown=mastodon:mastodon . /opt/mastodon COPY --link --chown=mastodon:mastodon --from=build /opt/mastodon /opt/mastodon ENV RAILS_ENV="production" \ From d805785e90058c774a692cc040dda1b0f7b7df69 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 15 Apr 2023 17:31:21 -0700 Subject: [PATCH 06/10] recompose, but with postgres:15-alpine --- docker-compose.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1991514424..be98d894e7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,16 +2,17 @@ version: '3' services: db: restart: always - image: postgres:14-alpine + image: postgres:15-alpine shm_size: 256mb networks: - internal_network healthcheck: test: ['CMD', 'pg_isready', '-U', 'postgres'] volumes: - - ./data/postgres14:/var/lib/postgresql/data + - ./data/postgres.15:/var/lib/postgresql/data environment: - 'POSTGRES_HOST_AUTH_METHOD=trust' + - 'POSTGRES_USER=mastodon' redis: restart: always @@ -21,7 +22,7 @@ services: healthcheck: test: ['CMD', 'redis-cli', 'ping'] volumes: - - ./redis:/data + - ./data/redis:/data # es: # restart: always @@ -82,7 +83,7 @@ services: # - es volumes: - ./public/system:/mastodon/public/system - - ./data/postgres14:/var/lib/postgresql/data + # - ./data/postgres:/var/lib/postgresql/data streaming: build: . From 047aa2c63d11af07f54047518625c3bbfc83e872 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 15 Apr 2023 17:44:15 -0700 Subject: [PATCH 07/10] re-export 3000 --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index be98d894e7..01ccab7e14 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,6 +69,8 @@ services: test: ['CMD-SHELL', 'wget -q --spider --proxy=off localhost:3000/health || exit 1'] expose: - 3000 + ports: + - 3000:3000 labels: - traefik.enable=true - traefik.http.routers.web.rule=Host(`social-dev.treehouse.systems`) From 4c6679ef334af036e8e2f1421d12c97e173d8ee1 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 15 Apr 2023 18:47:38 -0700 Subject: [PATCH 08/10] fix ci --- .woodpecker.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 5f7bdcf11c..01b845d4a3 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,15 +1,20 @@ variables: image: &docker-git docker:rc-git - volumes: - - &docker.sock /var/run/docker.sock:/var/run/docker.sock + volumes: &docker.sock + - /var/run/docker.sock:/var/run/docker.sock environment: common: &common-env NAME: gitea.treehouse.systems/treehouse/mastodon + docker-step: &docker-step + image: docker:rc-git + volumes: + - /var/run/docker.sock:/var/run/docker.sock + environment: + NAME: gitea.treehouse.systems/treehouse/mastodon pipeline: build: image: *docker-git - volumes: - - *docker.sock + volumes: *docker.sock environment: <<: *common-env commands: @@ -19,8 +24,7 @@ pipeline: tag-nightly: image: *docker-git - volumes: - - *docker.sock + volumes: *docker.sock environment: <<: *common-env commands: @@ -38,8 +42,7 @@ pipeline: push: image: *docker-git - volumes: - - *docker.sock + volumes: *docker.sock environment: <<: *common-env commands: From a00a7d1ce208130a783c1fe24c2a9fbc171f8cba Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 15 Apr 2023 18:51:48 -0700 Subject: [PATCH 09/10] forgot to save --- .woodpecker.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 01b845d4a3..bbe5c5cf6c 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -13,10 +13,7 @@ variables: NAME: gitea.treehouse.systems/treehouse/mastodon pipeline: build: - image: *docker-git - volumes: *docker.sock - environment: - <<: *common-env + <<: *docker-step commands: - docker version - docker image build -f Dockerfile --build-arg SOURCE_TAG=$CI_COMMIT_SHA . -t $NAME:latest From 2ff8fbd6e71f91414829425a8eb1deaa37aeb603 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 15 Apr 2023 18:54:02 -0700 Subject: [PATCH 10/10] oops --- .woodpecker.yml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index bbe5c5cf6c..9f70f5cef5 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,10 +1,4 @@ variables: - image: &docker-git docker:rc-git - volumes: &docker.sock - - /var/run/docker.sock:/var/run/docker.sock - environment: - common: &common-env - NAME: gitea.treehouse.systems/treehouse/mastodon docker-step: &docker-step image: docker:rc-git volumes: @@ -20,10 +14,7 @@ pipeline: - docker tag $NAME:latest $NAME:$CI_COMMIT_SHA tag-nightly: - image: *docker-git - volumes: *docker.sock - environment: - <<: *common-env + <<: *docker-step commands: - docker tag $NAME:latest $NAME:$(date -Idate -u) @@ -38,10 +29,7 @@ pipeline: # event: tag push: - image: *docker-git - volumes: *docker.sock - environment: - <<: *common-env + <<: *docker-step commands: - echo $REGISTRY_SECRET | docker login -u ariadne --password-stdin gitea.treehouse.systems - docker image push --all-tags $NAME