From e8fd392a23f4f0ddfcc4c9428878fdc10174eb83 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Thu, 6 Jul 2023 22:46:49 -0700 Subject: [PATCH] th: build more fast --- .dockerignore | 1 + .woodpecker.yml | 14 ++++++++++++- Dockerfile | 49 ++++++++++++++++++++++++++++------------------ app/models/list.rb | 2 +- app/models/user.rb | 2 +- docker-compose.yml | 3 ++- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/.dockerignore b/.dockerignore index 4df0f85c8f..bbbc9122f2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -22,6 +22,7 @@ build chart coverage data +db elasticsearch log neo4j diff --git a/.woodpecker.yml b/.woodpecker.yml index 02f6fd2da0..acfe0e3410 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -23,13 +23,25 @@ pipeline: - docker version - docker image build -f Dockerfile --build-arg SOURCE_TAG=$CI_COMMIT_SHA . --target build-base -t $NAME:build-base + build: + <<: *docker-step + commands: + - docker version + - docker image build -f Dockerfile --build-arg SOURCE_TAG=$CI_COMMIT_SHA . --target build -t $NAME:build + + output-base: + <<: *docker-step + commands: + - docker version + - docker image build -f Dockerfile --build-arg SOURCE_TAG=$CI_COMMIT_SHA . --target output-base -t $NAME:build + # the world is not yet ready for this step # test: # <<: *docker-step # commands: # - docker run --rm -e RAILS_ENV=test -e NODE_ENV=development $NAME:build-base sh -c 'bundle config set --local without development && bundle install && rake spec' - build: + output: <<: *docker-step commands: - eval $DATE_COMMAND diff --git a/Dockerfile b/Dockerfile index 7773a4636c..57cc60dd3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,11 @@ ARG NODE_IMAGE=node:18.16-bullseye-slim ARG RUBY_IMAGE=ghcr.io/moritzheiber/ruby-jemalloc:3.2.2-slim +# hadolint ignore=DL3006 FROM ${RUBY_IMAGE} as ruby # build-base +# hadolint ignore=DL3006 FROM ${NODE_IMAGE} as build-base COPY --link --from=ruby /opt/ruby /opt/ruby @@ -17,7 +19,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] WORKDIR /opt/mastodon -# hadolint ignore=DL3008 +# hadolint ignore=DL3008,DL3009 RUN --mount=type=cache,id=apt,target=/var/cache/apt,sharing=private \ set -eux && \ rm -f /etc/apt/apt.conf.d/docker-clean && \ @@ -47,6 +49,7 @@ ENV NODE_OPTIONS=--openssl-legacy-provider \ YARN_GLOBAL_FOLDER=/opt/yarn \ YARN_ENABLE_GLOBAL_CACHE=1 +# hadolint ignore=DL3060 RUN --mount=type=cache,id=bundle,target=/opt/bundle/cache,sharing=private \ --mount=type=cache,id=yarn,target=/opt/yarn/cache,sharing=private \ set -eux && \ @@ -89,20 +92,10 @@ RUN --mount=type=cache,id=yarn,target=/opt/yarn/cache,sharing=private \ bundle exec rails assets:precompile # final image -FROM ${NODE_IMAGE} as output - -# Use those args to specify your own version flags & suffixes -ARG SOURCE_TAG="" -ARG MASTODON_VERSION_FLAGS="" -ARG MASTODON_VERSION_SUFFIX="" - -ARG UID="991" -ARG GID="991" - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] +# hadolint ignore=DL3006 +FROM ${NODE_IMAGE} as output-base -ENV DEBIAN_FRONTEND="noninteractive" \ - PATH="${PATH}:/opt/ruby/bin:/opt/mastodon/bin" +ENV DEBIAN_FRONTEND="noninteractive" # Ignoring these here since we don't want to pin any versions and the Debian image removes apt-get content after use # hadolint ignore=DL3008,DL3009 @@ -110,10 +103,8 @@ RUN --mount=type=cache,id=apt,target=/var/cache/apt,sharing=private \ set -eux && \ rm -f /etc/apt/apt.conf.d/docker-clean && \ echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \ - apt-get update && \ echo "Etc/UTC" > /etc/localtime && \ - groupadd -g "${GID}" mastodon && \ - useradd -l -u "$UID" -g "${GID}" -m -d /opt/mastodon mastodon && \ + apt-get update && \ apt-get -y --no-install-recommends install \ ca-certificates \ ffmpeg \ @@ -130,8 +121,28 @@ RUN --mount=type=cache,id=apt,target=/var/cache/apt,sharing=private \ tini \ tzdata \ wget \ - whois \ - && ln -s /opt/mastodon /mastodon + whois + +# final image +FROM output-base as output + +# Use those args to specify your own version flags & suffixes +ARG SOURCE_TAG="" +ARG MASTODON_VERSION_FLAGS="" +ARG MASTODON_VERSION_SUFFIX="" + +ARG UID="991" +ARG GID="991" + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +ENV PATH="${PATH}:/opt/ruby/bin:/opt/mastodon/bin" + +# Ignoring these here since we don't want to pin any versions and the Debian image removes apt-get content after use +# hadolint ignore=DL3008,DL3009 +RUN groupadd -g "${GID}" mastodon && \ + useradd -l -u "$UID" -g "${GID}" -m -d /opt/mastodon mastodon && \ + ln -s /opt/mastodon /mastodon # 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 diff --git a/app/models/list.rb b/app/models/list.rb index 7dc96f01b3..fcef49e6e9 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -10,7 +10,7 @@ # created_at :datetime not null # updated_at :datetime not null # replies_policy :integer default("list"), not null -# exclusive :boolean default(FALSE) +# exclusive :boolean default(FALSE), not null # class List < ApplicationRecord diff --git a/app/models/user.rb b/app/models/user.rb index e5ec2447c1..c92771e66e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -100,7 +100,7 @@ class User < ApplicationRecord validates_with BlacklistedEmailValidator, if: -> { ENV['EMAIL_DOMAIN_LISTS_APPLY_AFTER_CONFIRMATION'] == 'true' || !confirmed? } validates_with EmailMxValidator, if: :validate_email_dns? validates :agreement, acceptance: { allow_nil: false, accept: [true, 'true', '1'] }, on: :create - validates :time_zone, inclusion: { in: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.name } }, allow_blank: true + # validates :time_zone, inclusion: { in: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.name } }, allow_blank: true # Honeypot/anti-spam fields attr_accessor :registration_form_time, :website, :confirm_password diff --git a/docker-compose.yml b/docker-compose.yml index 01ccab7e14..3a08046c3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -70,7 +70,8 @@ services: expose: - 3000 ports: - - 3000:3000 + - 127.0.0.1:3000:3000 + - '[::1]:3000:3000' labels: - traefik.enable=true - traefik.http.routers.web.rule=Host(`social-dev.treehouse.systems`)