diff --git a/.bash_profile b/.bash_profile new file mode 100644 index 00000000..46e7755c --- /dev/null +++ b/.bash_profile @@ -0,0 +1,6 @@ +# == Vim +export EDITOR=vim +set -o vi + +# == Starship +eval "$(starship init bash)" diff --git a/.bashrc b/.bashrc deleted file mode 100644 index d51a0c3a..00000000 --- a/.bashrc +++ /dev/null @@ -1,39 +0,0 @@ -# == Vim -export EDITOR=vim -set -o vi - -# == Homebrew -export HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew - -# == Nodenv -if command -v nodenv > /dev/null; then - eval "$(nodenv init -)" -fi - -# == Yarn -if command -v yarn > /dev/null; then - export PATH="$(yarn global bin):$PATH" -fi - -# == Rbenv -if command -v rbenv > /dev/null; then - eval "$(rbenv init -)" -fi - -# == Pyenv -if command -v pyenv > /dev/null; then - export PYENV_ROOT="$HOME/.pyenv" - export PATH="$PYENV_ROOT/bin:$PATH" - eval "$(pyenv init -)" -fi - -# == Poetry -export PATH="$HOME/.local/bin:$PATH" - -# == Starship -if command -v starship > /dev/null; then - eval "$(starship init bash)" -fi - -# == Shell -. ~/.bashrc.orig diff --git a/Brewfile b/Brewfile deleted file mode 100644 index 394bf1bd..00000000 --- a/Brewfile +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -# Programs: -brew "less" -brew "vim" -brew "curl" -brew "overmind" -brew "starship" - -# Languages: -brew "nodenv" -brew "rbenv" -brew "pyenv" - -# Libraries: -brew "libpq" -brew "libvips" -brew "ffmpeg" diff --git a/Dockerfile b/Dockerfile index 5abfa944..404ecec1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,51 +1,92 @@ # Configure base image -FROM homebrew/brew:4.1.21 +FROM debian:bookworm-slim -# Configure workdir and env +# Configure workdir WORKDIR /app -ENV RAILS_ENV=production RAILS_LOG_TO_STDOUT=true NODE_ENV=$RAILS_ENV -ENV BUNDLE_WITHOUT="development test" PYTHON_CONFIGURE_OPTS="--enable-shared" -# Install Homebrew packages -COPY --chown=linuxbrew Brewfile ./ -RUN brew bundle && brew cleanup - -# Configure shell -RUN mv "$HOME/.bashrc" "$HOME/.bashrc.orig" -COPY --chown=linuxbrew .bashrc .inputrc /home/linuxbrew/ -COPY --chown=linuxbrew starship.toml /home/linuxbrew/.config/starship.toml -SHELL ["/bin/bash", "--login", "-c"] - -# Configure languages -COPY --chown=linuxbrew .ruby-version .python-version .node-version ./ +# Install build dependencies +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get -y update -q \ + && apt-get install -yq --no-install-recommends --no-install-suggests curl tmux git bzip2 build-essential ca-certificates libyaml-dev libssl-dev libffi-dev libreadline-dev zlib1g-dev \ + && truncate -s 0 /var/log/*log # Install Ruby and Bundler -# ENV LANG=C.UTF-8 BUNDLE_JOBS=4 BUNDLE_RETRY=3 BUNDLE_APP_CONFIG=.bundle -RUN rbenv install +COPY .ruby-version ./ +RUN git clone --depth 1 https://github.com/rbenv/ruby-build.git \ + && PREFIX=/usr/local ./ruby-build/install.sh \ + && ruby-build "$(cat .ruby-version)" /usr/local \ + && rm -rf ./ruby-build # Install NodeJS and Yarn -RUN nodenv install && npm install -g yarn - -# Install Playwright -RUN yarn global add playwright && playwright install --with-deps +COPY .node-version ./ +RUN git clone --depth 1 https://github.com/nodenv/node-build.git \ + && PREFIX=/usr/local ./node-build/install.sh \ + && node-build "$(cat .node-version)" /usr/local \ + && npm install --global yarn \ + && npm cache clean --force \ + && rm -rf ./node-build # Install Python and Poetry -RUN pyenv install && pip3 install poetry +COPY .python-version ./ +ENV PYTHON_CONFIGURE_OPTS="--enable-shared" +RUN git clone --depth 1 --no-checkout https://github.com/pyenv/pyenv.git \ + && cd pyenv && git sparse-checkout set ./plugins/python-build \ + && cd .. && git checkout \ + && mv ./pyenv/plugins/python-build ./python-build && rm -r ./pyenv \ + && PREFIX=/usr/local ./python-build/install.sh \ + && python-build "$(cat .python-version)" /usr/local \ + && pip3 install --no-cache-dir poetry \ + && rm -rf ./python-build + +# Install runtime dependencies +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get -y update -q \ + && apt-get install -yq --no-install-recommends --no-install-suggests libpq-dev libvips ffmpeg \ + && truncate -s 0 /var/log/*log + +# Install Overmind +RUN curl -Lo /usr/bin/overmind.gz https://github.com/DarthSim/overmind/releases/download/v$OVERMIND_VERSION/overmind-v2.4.0-linux-amd64.gz \ + && gzip -d /usr/bin/overmind.gz \ + && chmod u+x /usr/bin/overmind + +# Install Playwright +RUN yarn global add playwright \ + && playwright install --with-deps \ + && yarn cache clean # Install Ruby dependencies -COPY --chown=linuxbrew Gemfile Gemfile.lock ./ +COPY Gemfile Gemfile.lock ./ +ENV BUNDLE_WITHOUT="development test" RUN bundle install --no-cache # Install NodeJS dependencies -COPY --chown=linuxbrew package.json yarn.lock ./ +COPY package.json yarn.lock ./ +ENV NODE_ENV=$RAILS_ENV RUN yarn install && yarn cache clean # Install Python dependencies -COPY --chown=linuxbrew pyproject.toml poetry.toml poetry.lock ./ +COPY pyproject.toml poetry.toml poetry.lock ./ RUN poetry install --no-root --no-cache --without=dev +# Install devtools +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get -y update -q \ + && apt-get install -yq --no-install-recommends --no-install-suggests vim less \ + && truncate -s 0 /var/log/*log + +# Configure shell +RUN curl -sS https://starship.rs/install.sh | sh +COPY .bash_profile .inputrc /root/ +COPY starship.toml /root/.config/starship.toml + +# Configure application environment +ENV RAILS_ENV=production RAILS_LOG_TO_STDOUT=true + # Copy application code -COPY --chown=linuxbrew . ./ +COPY . ./ # Precompile bootsnap code for faster boot times RUN bundle exec bootsnap precompile --gemfile app/ lib/ @@ -61,5 +102,4 @@ HEALTHCHECK --interval=15s --timeout=2s --start-period=10s --retries=3 \ CMD curl -f http://127.0.0.1:3000/status # Set entrypoint and default command -ENTRYPOINT [ "bash", "--login", "-c" ] CMD [ "bin/run" ]