Skip to content

Commit

Permalink
Play with docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmcal committed Oct 15, 2023
1 parent 49ac17d commit bc3cb75
Show file tree
Hide file tree
Showing 104 changed files with 17,069 additions and 16,998 deletions.
50 changes: 9 additions & 41 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ on:
- push
- pull_request

env:
RAILS_ENV: test
YARN_ENV: test

jobs:
build:
uses: gmmcal/gmmcal.com.br/.github/workflows/docker.yml@actions

backend:
name: 'Unit: Backend'
runs-on: ubuntu-20.04

container:
image: ruby:3.2.2
needs: build

services:
postgres:
Expand All @@ -28,40 +25,11 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v4

- uses: actions/cache@v3
- name: Download an image
uses: ishworkh/container-image-artifact-download@v1.0.0
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-gmmcal-
# languages
- name: Install APT dependencies
run: |
curl -sL https://deb.nodesource.com/setup_18.x | bash -
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get -yqq install nodejs libpq-dev
image: "gmmcal:test"

# dependencies
- name: Run bundle install
- name: Run rubocop
run: |
bundle config path vendor/bundle
bundle config set without development production
bundle install --jobs 4 --retry 3
- name: Setup database
run: |
bundle exec rails db:migrate
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_test

# script
- name: Run tests
run: |
bundle exec rspec
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true
docker run --network=${{ job.services.postgres.network }} -e DATABASE_URL='postgres://postgres:postgres@postgres:5432/gmmcalcombr_test' -e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true --rm gmmcal:test
25 changes: 25 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docker

on:
workflow_call:

jobs:
docker:
name: 'Docker: Build'
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4

- name: Build test image
uses: docker/build-push-action@v2
with:
push: false
context: .
target: test
tags: "gmmcal:test"

- name: Upload image
uses: ishworkh/container-image-artifact-upload@v1.0.0
with:
image: "gmmcal:test"
107 changes: 28 additions & 79 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,124 +4,73 @@ on:
- pull_request

jobs:
build:
uses: gmmcal/gmmcal.com.br/.github/workflows/docker.yml@actions

rubocop:
name: 'Lint: Rubocop'
runs-on: ubuntu-20.04

container:
image: ruby:3.2.2
uses: gmmcal/gmmcal.com.br/.github/workflows/docker.yml@actions

steps:
- uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-gmmcal-
- name: Run bundle install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Run rubocop
run: bundle exec rubocop --config .rubocop.yml .
run: |
docker run --rm gmmcal:test bundle exec rubocop --config .rubocop.yml .
reek:
name: 'Lint: Reek'
runs-on: ubuntu-20.04

container:
image: ruby:3.2.2
uses: gmmcal/gmmcal.com.br/.github/workflows/docker.yml@actions

steps:
- uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-gmmcal-
- name: Run bundle install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Run reek
run: bundle exec reek --config .reek.yml .
run: |
docker run --rm gmmcal:test bundle exec reek --config .reek.yml .
brakeman:
name: 'Lint: Brakeman'
runs-on: ubuntu-20.04

container:
image: ruby:3.2.2
needs: build

steps:
- uses: actions/checkout@v4

- uses: actions/cache@v3
- name: Download an image
uses: ishworkh/container-image-artifact-download@v1.0.0
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-gmmcal-
- name: Run bundle install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
image: "gmmcal:test"

- name: Run brakeman
run: bundle exec brakeman
run: |
docker run --rm gmmcal:test bundle exec brakeman
bundler-audit:
name: 'Lint: Bundler Audit'
runs-on: ubuntu-20.04

container:
image: ruby:3.2.2
needs: build

steps:
- uses: actions/checkout@v4

- name: Install Bundler Audit
run: gem install bundler-audit

- name: Update advisory database
run: bundler-audit update
- name: Download an image
uses: ishworkh/container-image-artifact-download@v1.0.0
with:
image: "gmmcal:test"

- name: Run bundler-audit
run: bundler-audit
run: |
docker run --rm gmmcal:test bundle exec bundler-audit update && bundle exec bundler-audit
scsslint:
name: 'Lint: SCSSLint'
runs-on: ubuntu-20.04

container:
image: ruby:3.2.2
needs: build

steps:
- uses: actions/checkout@v4

- uses: actions/cache@v3
- name: Download an image
uses: ishworkh/container-image-artifact-download@v1.0.0
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-gmmcal-
- name: Run bundle install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
image: "gmmcal:test"

- name: Run SCSSLint
run: bundle exec scss-lint --config .scss-lint.yml
run: |
docker run --rm gmmcal:test bundle exec scss-lint --config .scss-lint.yml
eslint:
name: 'Lint: ESLint'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ capybara-*.html
/public/assets
/public/uploads
/coverage/
!/coverage/.keep
/spec/tmp
/spec/backend/examples.txt
/spec/end-to-end/screenshots
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require:
- rubocop-rails
- rubocop-rspec
- rubocop-factory_bot

AllCops:
TargetRubyVersion: 3.0
Expand Down
11 changes: 5 additions & 6 deletions .scss-lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Default application configuration that all configurations inherit from.

scss_files: "app/**/*.scss"
scss_files: "scss/**/*.scss"
plugin_directories: ['.scss-linters']

exclude:
- 'app/assets/stylesheets/admin/mdb/**'
- 'app/javascript/stylesheets/components/skill.scss'
- 'app/assets/stylesheets/cv/_functions.scss'
- 'app/assets/stylesheets/cv/application.sass.scss'
- 'app/assets/stylesheets/frontend/components/skill.scss'
- 'scss/admin/mdb/**'
- 'scss/cv/_functions.scss'
- 'scss/cv/application.sass.scss'
- 'scss/frontend/components/skill.scss'

# List of gem names to load custom linters from (make sure they are already
# installed)
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,24 @@ ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["bundle", "exec", "rspec"]

# Cypress Test image - WIP
FROM cypress/included as cypress

WORKDIR /rails

# Copy application code
COPY . .

# Run and own only the runtime files as a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
chown -R rails:rails .
USER rails:rails

RUN ls -la

# Entrypoint prepares the database.
# ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
CMD ["cypress", "run", "-c", "'{\"e2e\": {\"baseUrl\":\"http://web:3000\"}}'"]
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ group :development do
gem 'listen'
gem 'reek'
gem 'rubocop'
gem 'rubocop-factory_bot'
gem 'rubocop-rails'
gem 'rubocop-rspec'
gem 'scss_lint', require: false
Expand All @@ -55,6 +56,7 @@ group :test do
end

group :test, :development do
gem 'bundler-audit'
gem 'cypress-on-rails'
end

Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ GEM
msgpack (~> 1.2)
brakeman (6.0.1)
builder (3.2.4)
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
Expand Down Expand Up @@ -343,6 +346,7 @@ PLATFORMS
DEPENDENCIES
bootsnap
brakeman
bundler-audit
cypress-on-rails
database_cleaner
devise
Expand All @@ -361,6 +365,7 @@ DEPENDENCIES
reek
rspec-rails
rubocop
rubocop-factory_bot
rubocop-rails
rubocop-rspec
scss_lint
Expand Down
Loading

0 comments on commit bc3cb75

Please sign in to comment.