Skip to content

Commit

Permalink
Merge pull request #5 from emakrashov/docker-image-update
Browse files Browse the repository at this point in the history
Update CI/CD workflow to include Docker image push
  • Loading branch information
emkshv committed Jun 26, 2023
2 parents 82397f0 + 42138ed commit b15acf5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 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
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
Rails 7.1, Devise, Docker, Docker Compose, Graphana
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

Before starting, make sure you have Docker and Docker Compose installed.

##### Clone the Repository
#### Clone the repository

```
git clone https://github.com/emakrashov/rails-docker.git
git clone https://github.com/rails-starter-docker-app/rails-docker
cd rails-docker
```

##### Setup Environment Variables
#### Setup environment variables

Copy `.env.example` to `.env` in the root directory of the project

Expand All @@ -28,7 +32,7 @@ RAILS_DOCKER_POSTGRES_PASSWORD=your_postgres_password

These values will be used by Docker Compose for database configuration.

##### Build and Run the Application
#### Build and run the application

Use Docker Compose to build and start the services defined in the `docker-compose.yml` file.

Expand All @@ -40,13 +44,13 @@ docker-compose up

This will build the Docker image and start the application and database services.

##### Access the Application
#### Access the application

The application should now be running at http://localhost:3000.

### How to run tests locally

##### Prepare the Test Database:
#### Prepare the test database:

Run the following command to create and set up the test database:

Expand All @@ -56,7 +60,7 @@ rails db:test:prepare

*Note: If you update your database schema (e.g., via migrations), you should run this command again to update the schema in the test database.*

Now you can run the tests with the following command:
Now you can run the tests:

```
rails test
Expand Down

0 comments on commit b15acf5

Please sign in to comment.