-
Notifications
You must be signed in to change notification settings - Fork 3
Rewrite it in Zig #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gaffneyc
wants to merge
1
commit into
main
Choose a base branch
from
zig
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rewrite it in Zig #436
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,3 @@ | ||
| # See http://help.github.com/ignore-files/ for more about ignoring files. | ||
| # | ||
| # If you find yourself ignoring temporary files generated by your text editor | ||
| # or operating system, you probably want to add a global ignore instead: | ||
| # git config --global core.excludesfile ~/.gitignore_global | ||
|
|
||
| # Ignore bundler config | ||
| /.bundle | ||
|
|
||
| # Ignore the default SQLite database. | ||
| /db/*.sqlite3 | ||
|
|
||
| # Ignore all logfiles and tempfiles. | ||
| /log/*.log | ||
| /tmp | ||
|
|
||
| # Ignore application configuration | ||
| /config/application.yml | ||
|
|
||
| /app/assets/builds/* | ||
| !/app/assets/builds/.keep | ||
|
|
||
| /node_modules | ||
| # Zig build artifacts | ||
| /.zig-cache/ | ||
| /zig-out/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [tools] | ||
| zig = "0.15" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,96 +1,24 @@ | ||
| # syntax=docker/dockerfile:1 | ||
| # check=error=true | ||
| FROM debian:stable-slim AS builder | ||
|
|
||
| # Make sure RUBY_VERSION matches the Ruby version in .ruby-version | ||
| ARG RUBY_VERSION=3.4.4 | ||
| FROM ruby:$RUBY_VERSION-alpine AS base | ||
| # Install Zig | ||
| RUN apt-get update && apt-get install -y curl xz-utils && \ | ||
| curl -L https://ziglang.org/download/0.15.2/zig-x86_64-linux.tar.xz | tar xJ && \ | ||
| mv zig-* /opt/zig | ||
|
|
||
| LABEL fly_launch_runtime="rails" | ||
|
|
||
| # Rails app lives here | ||
| WORKDIR /rails | ||
|
|
||
| # Update gems and bundler | ||
| RUN gem update --system --no-document && \ | ||
| gem install -N bundler | ||
|
|
||
| # Install base packages | ||
| RUN apk add --no-cache curl jemalloc postgresql-client tzdata | ||
|
|
||
| # Set production environment | ||
| ENV BUNDLE_DEPLOYMENT="1" \ | ||
| BUNDLE_PATH="/usr/local/bundle" \ | ||
| BUNDLE_WITHOUT="development:test" \ | ||
| RAILS_ENV="production" | ||
|
|
||
|
|
||
| # Throw-away build stages to reduce size of final image | ||
| FROM base AS prebuild | ||
|
|
||
| # Install packages needed to build gems and node modules | ||
| RUN apk add --no-cache build-base git gyp libpq-dev pkgconfig python3 yaml-dev | ||
|
|
||
|
|
||
| FROM prebuild AS node | ||
|
|
||
| # Install Node.js | ||
| ARG NODE_VERSION=22.4.0 | ||
| ENV PATH=/usr/local/node/bin:$PATH | ||
| RUN curl -sL https://unofficial-builds.nodejs.org/download/release/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64-musl.tar.gz | tar xz -C /tmp/ && \ | ||
| mkdir /usr/local/node && \ | ||
| cp -rp /tmp/node-v${NODE_VERSION}-linux-x64-musl/* /usr/local/node/ && \ | ||
| rm -rf /tmp/node-v${NODE_VERSION}-linux-x64-musl | ||
|
|
||
| # Install node modules | ||
| COPY package.json ./ | ||
| RUN npm install | ||
|
|
||
|
|
||
| FROM prebuild AS build | ||
|
|
||
| # Install application gems | ||
| COPY Gemfile Gemfile.lock .ruby-version ./ | ||
| RUN bundle install && \ | ||
| rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ | ||
| bundle exec bootsnap precompile --gemfile | ||
|
|
||
| # Copy node modules | ||
| COPY --from=node /rails/node_modules /rails/node_modules | ||
| COPY --from=node /usr/local/node /usr/local/node | ||
| ENV PATH=/usr/local/node/bin:$PATH | ||
|
|
||
| # Copy application code | ||
| WORKDIR /app | ||
| COPY . . | ||
|
|
||
| # Precompile bootsnap code for faster boot times | ||
| RUN bundle exec bootsnap precompile app/ lib/ | ||
|
|
||
| # Adjust binfiles to set current working directory | ||
| RUN grep -l '#!/usr/bin/env ruby' /rails/bin/* | xargs sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' | ||
|
|
||
| # Precompiling assets for production without requiring secret RAILS_MASTER_KEY | ||
| RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile | ||
|
|
||
|
|
||
| # Final stage for app image | ||
| FROM base | ||
|
|
||
| # Install packages needed for deployment | ||
| RUN apk add --no-cache gzip libpq | ||
| ENV PATH="/opt/zig:$PATH" | ||
| RUN zig build -Doptimize=ReleaseSafe | ||
|
|
||
| # Copy built artifacts: gems, application | ||
| COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" | ||
| COPY --from=build /rails /rails | ||
| FROM debian:stable-slim | ||
|
|
||
| # Run and own only the runtime files as a non-root user for security | ||
| RUN addgroup --system --gid 1000 rails && \ | ||
| adduser --system rails --uid 1000 --ingroup rails --home /home/rails --shell /bin/sh rails && \ | ||
| chown -R 1000:1000 db log tmp | ||
| USER 1000:1000 | ||
| # Install CA certificates for outbound HTTPS (triggers) | ||
| RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Entrypoint sets up the container. | ||
| ENTRYPOINT ["/rails/bin/docker-entrypoint"] | ||
| COPY --from=builder /app/zig-out/bin/buildlight /usr/local/bin/buildlight | ||
| # Copy public files for Fly.io [[statics]] to serve | ||
| COPY --from=builder /app/public /app/public | ||
|
|
||
| # Start the server by default, this can be overwritten at runtime | ||
| EXPOSE 3000 | ||
| CMD ["./bin/rails", "server"] | ||
| EXPOSE 8080 | ||
| CMD ["buildlight"] | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dockerfile downloads the Zig toolchain via
curl ... | tarfromziglang.orgwithout any checksum or signature verification. If the download endpoint or TLS channel is compromised, an attacker could supply a malicious compiler that injects backdoors into the builtbuildlightbinary. Pin the archive with a strong hash or use a base image or package manager that provides integrity verification for Zig.