Skip to content

Commit

Permalink
Update CI/CD workflow to include Docker image push
Browse files Browse the repository at this point in the history
  • Loading branch information
emkshv committed Jun 26, 2023
1 parent 6d3027e commit 42138ed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
29 changes: 25 additions & 4 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 }}
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
ARG RUBY_VERSION=3.2.2
FROM ruby:$RUBY_VERSION

RUN set -e

# Rails app lives here
WORKDIR /rails

# Set production environment
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 ./
Expand All @@ -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"]
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 42138ed

Please sign in to comment.