From 42138ed8e2746b6b7fe0ef022b4df65617037694 Mon Sep 17 00:00:00 2001 From: Evgenii Makrashov Date: Mon, 26 Jun 2023 02:34:03 +0200 Subject: [PATCH] Update CI/CD workflow to include Docker image push --- .github/workflows/rubyonrails.yml | 29 +++++++++++++++++++++++++---- Dockerfile | 10 ++++++++-- README.md | 6 +++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index 2f3d51b..99a195e 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -28,15 +28,12 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - # Add or replace dependency steps here - name: Install Ruby and gems uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 with: bundler-cache: true - # Add or replace database setup steps here - name: Set up database schema run: bin/rails db:schema:load - # Add or replace test runners here - name: Run tests run: bin/rake @@ -49,10 +46,34 @@ jobs: uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 with: bundler-cache: true - # Add or replace any other lints here - name: Security audit dependencies run: bin/bundler-audit --update - name: Security audit application code run: bin/brakeman -q -w2 - name: Lint Ruby files run: bin/rubocop --parallel + + docker: + needs: [test, lint] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Login to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ secrets.DOCKER_HUB_REPOSITORY }} + + - name: Build and push Docker image + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index e84d79d..3ba0b4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ ARG RUBY_VERSION=3.2.2 FROM ruby:$RUBY_VERSION +RUN set -e + # Rails app lives here WORKDIR /rails @@ -9,7 +11,8 @@ WORKDIR /rails ENV RAILS_LOG_TO_STDOUT="1" \ RAILS_SERVE_STATIC_FILES="true" \ RAILS_ENV="production" \ - BUNDLE_WITHOUT="development" + BUNDLE_WITHOUT="development" \ + SECRET_KEY_BASE_DUMMY=1 # Install application gems COPY Gemfile Gemfile.lock ./ @@ -21,8 +24,11 @@ COPY . . # Precompile bootsnap code for faster boot times RUN bundle exec bootsnap precompile --gemfile app/ lib/ +# # Precompiling assets for production without requiring secret RAILS_MASTER_KEY +# RUN bundle exec rails assets:precompile + # Precompiling assets for production without requiring secret RAILS_MASTER_KEY -RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile +RUN SECRET_KEY_BASE=$(bin/rails secret) bundle exec rails assets:precompile # Entrypoint prepares the database. ENTRYPOINT ["/rails/bin/docker-entrypoint"] diff --git a/README.md b/README.md index 3f47f84..155e9cd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -A starter Rails 7.1 application with Devise authentication with DaisyUI, Grafana and Prometheus metrics, and Docker configuration. +A mini-starter Rails 7.0.5 web application + +- Devise authentication with DaisyUI forms +- Grafana and Prometheus metrics (using the Yabeda framework) +- Docker container ### How to run the application using Docker