diff --git a/.env b/.env index 2f6080e..b0fe633 100644 --- a/.env +++ b/.env @@ -8,3 +8,4 @@ DATABASE_URL_test=postgres://postgres:postgres@postgres/tracking_test # Various other things RAILS_ENV=development +INCONTAINER=true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ebfe14f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +name: CI + +on: + pull_request: + push: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3 + + # redis: + # image: redis + # ports: + # - 6379:6379 + # options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - name: Install packages + run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libjemalloc2 libvips postgresql-client libpq-dev + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Run tests + env: + RAILS_ENV: test + DATABASE_URL: postgres://postgres:postgres@localhost:5432 + # REDIS_URL: redis://localhost:6379/0 + run: bin/rails spec + # run: bin/rails db:test:prepare spec + + # - name: Keep screenshots from failed system tests + # uses: actions/upload-artifact@v4 + # if: failure() + # with: + # name: screenshots + # path: ${{ github.workspace }}/tmp/capybara + # if-no-files-found: ignore diff --git a/.gitignore b/.gitignore index 5fb66c9..16f1145 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,9 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +# Other random stuff +spec/examples.txt + +/app/assets/builds/* +!/app/assets/builds/.keep diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..9a8e706 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--color +--require spec_helper +--format Fuubar diff --git a/.rubocop.yml b/.rubocop.yml index 4bf5098..03e4e9f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ require: - rubocop-capybara - rubocop-rails + - rubocop-rspec AllCops: UseCache: false diff --git a/Dockerfile b/Dockerfile index 005b703..b93f116 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ WORKDIR /app # Set production environment ENV RAILS_ENV="production" \ - BUNDLE_DEPLOYMENT="1" \ + # BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ BUNDLE_WITHOUT="development" @@ -42,9 +42,54 @@ COPY . . RUN bundle exec bootsnap precompile app/ lib/ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY -# RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rake assets:precompile -# RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile - +RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile + +# Latest chromedriver to control browser tests +ARG DEBIAN_FRONTEND=noninteractive +SHELL ["/bin/bash", "-c"] +RUN SYSTEM_ARCH=$(arch | sed s/aarch64/arm64/) && \ + if [ "$SYSTEM_ARCH" = "amd64" ]; then \ + mkdir -p /etc/apt/keyrings && \ + curl -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | tee /etc/apt/keyrings/chrome.asc && \ + echo "deb [signed-by=/etc/apt/keyrings/chrome.asc arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google.list && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + google-chrome-stable && \ + rm -rf /var/lib/apt/lists/* && \ + CHROMEDRIVER_VERSION=$(curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE) && \ + mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \ + curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \ + unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \ + rm /tmp/chromedriver_linux64.zip && \ + chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \ + ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver ; \ + else \ + apt-get update && \ + echo "============================ 1 =============================" && \ + apt-get install -y --no-install-recommends debian-archive-keyring && \ + echo "============================ 2 =============================" && \ + echo $'Explanation: Allow installing chromium from the debian repo. \n\ +Package: chromium* \n\ +Pin: origin "*.debian.org" \n\ +Pin-Priority: 100 \n\ +\n\ +Explanation: Avoid other packages from the debian repo. \n\ +Package: * \n\ +Pin: origin "*.debian.org" \n\ +Pin-Priority: 1 \n\ +' > /etc/apt/preferences.d/debian-chromium && \ + cat /etc/apt/preferences.d/debian-chromium && \ + echo "============================ 3 =============================" && \ + apt-get update && \ + echo "============================ 4 =============================" && \ + apt-get install -y --no-install-recommends chromium chromium-driver && \ + echo "============================ 5 =============================" && \ + ln -s $(which chromium) /usr/bin/google-chrome && \ + echo "============================ 6 =============================" && \ + rm -rf /var/lib/apt/lists/* && \ + echo "============================ 7 =============================" && \ + echo "Chromium installed for $SYSTEM_ARCH" ; \ + fi # Final stage for app image FROM base @@ -67,4 +112,4 @@ COPY --from=build /app /app ENTRYPOINT ["/app/bin/docker-entrypoint"] # Start the server by default, this can be overwritten at runtime -CMD ["./bin/rails", "server", "-b", "0.0.0.0"] +CMD ["bin/start_server"] diff --git a/Gemfile b/Gemfile index 8f08a5c..1a3d0bc 100644 --- a/Gemfile +++ b/Gemfile @@ -50,10 +50,16 @@ gem "bootsnap", require: false group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[mri windows] + gem "foreman" + gem "rubocop", "1.56.3" + gem "rubocop-capybara" gem "rubocop-rails" + gem "rubocop-rspec" - gem "rubocop-capybara" + gem "rspec-rails", "~> 6.1.0" + + gem "fuubar" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 9c4e7a7..d73e6e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,8 +100,13 @@ GEM debug (1.9.2) irb (~> 1.10) reline (>= 0.3.8) + diff-lcs (1.5.1) drb (2.2.1) erubi (1.12.0) + foreman (0.88.1) + fuubar (2.5.1) + rspec-core (~> 3.0) + ruby-progressbar (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.5) @@ -211,6 +216,23 @@ GEM reline (0.5.7) io-console (~> 0.5) rexml (3.2.6) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-rails (6.1.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) rubocop (1.56.3) base64 (~> 0.1.1) json (~> 2.3) @@ -227,11 +249,20 @@ GEM parser (>= 3.3.1.0) rubocop-capybara (2.20.0) rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) rubocop-rails (2.24.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rspec (2.29.2) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) ruby-progressbar (1.13.0) rubyzip (2.3.2) selenium-webdriver (4.16.0) @@ -295,14 +326,18 @@ DEPENDENCIES bootsnap capybara debug + foreman + fuubar importmap-rails jbuilder pg (~> 1.1) puma (>= 5.0) rails (~> 7.1.3, >= 7.1.3.2) + rspec-rails (~> 6.1.0) rubocop (= 1.56.3) rubocop-capybara rubocop-rails + rubocop-rspec selenium-webdriver sprockets-rails stimulus-rails diff --git a/Procfile.dev b/Procfile.dev new file mode 100644 index 0000000..3a28793 --- /dev/null +++ b/Procfile.dev @@ -0,0 +1,2 @@ +web: bin/rails server -b "0.0.0.0" +css: bin/rails tailwindcss:watch diff --git a/test/controllers/.keep b/app/assets/builds/.keep similarity index 100% rename from test/controllers/.keep rename to app/assets/builds/.keep diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 5918193..338a0e8 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,2 +1,3 @@ //= link_tree ../images //= link_directory ../stylesheets .css +//= link_tree ../builds diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index 288b9ab..07b1c92 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -13,3 +13,7 @@ *= require_tree . *= require_self */ + +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..941c3a2 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + def index + # @users = User.all + end +end diff --git a/app/views/home/index.erb b/app/views/home/index.erb new file mode 100644 index 0000000..6218c8b --- /dev/null +++ b/app/views/home/index.erb @@ -0,0 +1,3 @@ +