Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Setup release and docker builds CI & CD (#13651)
Damian Legawiecbe1f3ee95ec3
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlnew file mode 100644index 0000000000..095a84797b--- /dev/null+++ b/.github/workflows/release.yml@@ -0,0 +1,74 @@+name: Release++on:+ push:+ tags: ['v*']++jobs:+ release-gems:+ name: Release gems to RubyGems+ runs-on: ubuntu-latest+ environment: release+ permissions:+ contents: write+ id-token: write++ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '3.3'+ bundler-cache: true+ working-directory: spree++ - name: Configure RubyGems credentials+ uses: rubygems/configure-rubygems-credentials@main++ - name: Build and push gems to RubyGems+ working-directory: spree+ run: bundle exec rake gem:release++ release-docker:+ name: Release Docker image+ needs: release-gems+ runs-on: ubuntu-latest+ permissions:+ contents: read+ packages: write++ env:+ REGISTRY: ghcr.io+ IMAGE_NAME: spree/spree++ steps:+ - uses: actions/checkout@v4++ - uses: docker/setup-qemu-action@v3++ - uses: docker/setup-buildx-action@v3++ - uses: docker/login-action@v3+ with:+ registry: ${{ env.REGISTRY }}+ username: ${{ github.actor }}+ password: ${{ secrets.GITHUB_TOKEN }}++ - uses: docker/metadata-action@v5+ id: meta+ with:+ images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}+ tags: |+ type=semver,pattern={{version}}+ type=semver,pattern={{major}}.{{minor}}++ - uses: docker/build-push-action@v6+ with:+ context: .+ file: server/Dockerfile.release+ push: true+ tags: ${{ steps.meta.outputs.tags }}+ labels: ${{ steps.meta.outputs.labels }}+ platforms: linux/amd64,linux/arm64+ cache-from: type=gha+ cache-to: type=gha,mode=maxdiff --git a/server/Dockerfile b/server/Dockerfileindex 791755ace1..ac45bf84d7 100644--- a/server/Dockerfile+++ b/server/Dockerfile@@ -30,7 +30,7 @@ COPY spree/ /spree/# Install application gemsCOPY server/vendor/ ./vendor/-COPY server/Gemfile server/Gemfile.lock ./+COPY server/Gemfile.common server/Gemfile server/Gemfile.lock ./RUN bundle install && \rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.gitdiff --git a/server/Dockerfile.release b/server/Dockerfile.releasenew file mode 100644index 0000000000..a7c928edf7--- /dev/null+++ b/server/Dockerfile.release@@ -0,0 +1,104 @@+# syntax=docker/dockerfile:1+# check=error=true++# Make sure RUBY_VERSION matches the Ruby version in .ruby-version+ARG RUBY_VERSION=4.0.1+FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base++# Rails app lives here+WORKDIR /rails++# Install base packages+RUN apt-get update -qq && \+ apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \+ ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \+ rm -rf /var/lib/apt/lists /var/cache/apt/archives++ENV BUNDLE_PATH="/usr/local/bundle" \+ LD_PRELOAD="/usr/local/lib/libjemalloc.so" \+ RAILS_ENV="production"++# Stage 1: Build Spree gems from source+FROM base AS gems++RUN apt-get update -qq && \+ apt-get install --no-install-recommends -y build-essential git && \+ rm -rf /var/lib/apt/lists /var/cache/apt/archives++COPY spree/ /spree/+WORKDIR /spree++# Build all Spree .gem files with proper versioned names+RUN mkdir -p /gems && \+ cd core && gem build spree_core.gemspec && mv *.gem /gems/ && cd .. && \+ cd api && gem build spree_api.gemspec && mv *.gem /gems/ && cd .. && \+ gem build spree.gemspec && mv *.gem /gems/ && \+ cd emails && gem build spree_emails.gemspec && mv *.gem /gems/ && cd .. && \+ cd admin && gem build spree_admin.gemspec && mv *.gem /gems/ && cd .. && \+ ruby -r ./core/lib/spree/core/version -e 'puts Spree::VERSION' > /gems/VERSION++# Stage 2: Build application+FROM base AS build++# Install packages needed to build gems+RUN apt-get update -qq && \+ apt-get install --no-install-recommends -y build-essential git libpq-dev libyaml-dev pkg-config && \+ rm -rf /var/lib/apt/lists /var/cache/apt/archives++# Copy locally-built Spree gems+COPY --from=gems /gems/ /gems/++# Create a local gem repository index so Bundler can resolve Spree gems from it+RUN mkdir -p /local-gems/gems && cp /gems/*.gem /local-gems/gems/ && \+ gem generate_index --directory /local-gems++# Install application gems+COPY server/Gemfile.common server/Gemfile.release ./+RUN cp Gemfile.release Gemfile++# Resolve and install gems (SPREE_VERSION env var tells Gemfile.release which version to pin)+# After install, write a frozen Gemfile that hardcodes versions (no env var or local source at runtime)+RUN SPREE_VERSION=$(cat /gems/VERSION) && export SPREE_VERSION && \+ bundle config set --local without 'development test' && \+ bundle lock && \+ bundle install && \+ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \+ rm -rf /local-gems /gems && \+ cp Gemfile.common /tmp/Gemfile.frozen && \+ echo "" >> /tmp/Gemfile.frozen && \+ echo "gem 'spree', '$SPREE_VERSION'" >> /tmp/Gemfile.frozen && \+ echo "gem 'spree_core', '$SPREE_VERSION'" >> /tmp/Gemfile.frozen && \+ echo "gem 'spree_api', '$SPREE_VERSION'" >> /tmp/Gemfile.frozen && \+ echo "gem 'spree_emails', '$SPREE_VERSION'" >> /tmp/Gemfile.frozen && \+ echo "gem 'spree_admin', '$SPREE_VERSION'" >> /tmp/Gemfile.frozen && \+ echo "gem 'spree_stripe', github: 'spree/spree_stripe'" >> /tmp/Gemfile.frozen && \+ echo "gem 'spree_i18n'" >> /tmp/Gemfile.frozen && \+ cp Gemfile.lock /tmp/Gemfile.lock.frozen++# Copy application code (overwrites Gemfile/lockfile with dev versions)+COPY server/ .++# Restore frozen Gemfile/lockfile (no eval_gemfile, no env vars, no local sources)+RUN cp /tmp/Gemfile.frozen Gemfile && cp /tmp/Gemfile.lock.frozen Gemfile.lock && \+ rm -f Gemfile.common Gemfile.release++# Precompile assets+RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile++# Stage 3: Runtime+FROM base++# Run and own only the runtime files as a non-root user for security+RUN groupadd --system --gid 1000 rails && \+ useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash+USER 1000:1000++# Copy built artifacts: gems, application+COPY --chown=rails:rails --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"+COPY --chown=rails:rails --from=build /rails /rails++# Entrypoint prepares the database.+ENTRYPOINT ["/rails/bin/docker-entrypoint"]++EXPOSE 3000+CMD ["./bin/rails", "server", "-b", "0.0.0.0"]diff --git a/server/Gemfile b/server/Gemfileindex be3c13032b..84e9c66f00 100644--- a/server/Gemfile+++ b/server/Gemfile@@ -1,41 +1,10 @@-source "https://rubygems.org"+eval_gemfile("Gemfile.common")-# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"-gem "rails", "~> 8.1.2"-# The modern asset pipeline for Rails [https://github.com/rails/propshaft]-gem "propshaft"-# Use postgresql as the database for Active Record-gem "pg", "~> 1.1"-# Use the Puma web server [https://github.com/puma/puma]-gem "puma", ">= 5.0"-# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]-gem "importmap-rails"-# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]-gem "turbo-rails"-# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]-gem "stimulus-rails"-# Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]-gem "tailwindcss-rails"--# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]-# gem "bcrypt", "~> 3.1.7"--# Windows does not include zoneinfo files, so bundle the tzinfo-data gem-gem "tzinfo-data", platforms: %i[ windows jruby ]--# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable-gem "solid_cache"-gem "solid_queue"-gem "solid_cable"--# Reduces boot times through caching; required in config/boot.rb-gem "bootsnap", require: false--# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]-gem "thruster", require: false--# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]-gem "image_processing", "~> 1.2"+gem "spree", path: "../spree"+gem "spree_emails", path: "../spree/emails"+gem "spree_admin", path: "../spree/admin"+gem "spree_stripe", github: "spree/spree_stripe"+gem "spree_i18n"group :development, :test do# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem@@ -49,22 +18,14 @@ group :development, :test do# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]gem "rubocop-rails-omakase", require: false-end--group :development do- # Use console on exceptions pages [https://github.com/rails/web-console]- gem "web-console"-end-gem "devise"-gem "spree", path: "../spree"-gem "spree_emails", path: "../spree/emails"-gem "spree_admin", path: "../spree/admin"-gem "spree_stripe", github: "spree/spree_stripe"-gem "spree_i18n"-group :development, :test dogem "spree_dev_tools"gem "letter_opener"gem "listen"gem "simplecov-cobertura"end++group :development do+ # Use console on exceptions pages [https://github.com/rails/web-console]+ gem "web-console"+enddiff --git a/server/Gemfile.common b/server/Gemfile.commonnew file mode 100644index 0000000000..809d58fac3--- /dev/null+++ b/server/Gemfile.common@@ -0,0 +1,40 @@+source "https://rubygems.org"++# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"+gem "rails", "~> 8.1.2"+# The modern asset pipeline for Rails [https://github.com/rails/propshaft]+gem "propshaft"+# Use postgresql as the database for Active Record+gem "pg", "~> 1.1"+# Use the Puma web server [https://github.com/puma/puma]+gem "puma", ">= 5.0"+# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]+gem "importmap-rails"+# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]+gem "turbo-rails"+# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]+gem "stimulus-rails"+# Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]+gem "tailwindcss-rails"++# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]+# gem "bcrypt", "~> 3.1.7"++# Windows does not include zoneinfo files, so bundle the tzinfo-data gem+gem "tzinfo-data", platforms: %i[ windows jruby ]++# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable+gem "solid_cache"+gem "solid_queue"+gem "solid_cable"++# Reduces boot times through caching; required in config/boot.rb+gem "bootsnap", require: false++# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]+gem "thruster", require: false++# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]+gem "image_processing", "~> 1.2"++gem "devise"diff --git a/server/Gemfile.lock b/server/Gemfile.lockindex 0471fc4cdb..6469e23cda 100644--- a/server/Gemfile.lock+++ b/server/Gemfile.lock@@ -77,7 +77,6 @@ PATHphonelib (~> 0.10)rails (>= 7.2, < 8.2)ransack (>= 4.1)- request_store (~> 1.7)rexmlruby-oembed (~> 0.18)safely_block (~> 0.4)diff --git a/server/Gemfile.release b/server/Gemfile.releasenew file mode 100644index 0000000000..ce627f82b7--- /dev/null+++ b/server/Gemfile.release@@ -0,0 +1,16 @@+eval_gemfile("Gemfile.common")++# Spree gems built from source (served from local gem repository during Docker build)+# The SPREE_VERSION environment variable is set during the Docker build+spree_version = ENV.fetch("SPREE_VERSION", "0")++source "file:///local-gems" do+ gem "spree", spree_version+ gem "spree_core", spree_version+ gem "spree_api", spree_version+ gem "spree_emails", spree_version+ gem "spree_admin", spree_version+end++gem "spree_stripe", github: "spree/spree_stripe"+gem "spree_i18n"