Skip to content

Commit

Permalink
Move final steps to run on docker for github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmcal committed Oct 25, 2023
1 parent 4ae2fcb commit aa78fe8
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 51 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ on:
command:
type: string
required: true
image:
type: string
required: false
default: gmmcal/gmmcal:test

jobs:
lint:
name: Lint
runs-on: ubuntu-20.04

steps:
- name: Execute linter
run: docker run --rm gmmcal/gmmcal:test ${{ inputs.command }}
- name: Execute ${{ inputs.command }}
run: docker run --rm ${{ inputs.image }} ${{ inputs.command }}
72 changes: 31 additions & 41 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,53 +64,43 @@ jobs:
needs: [build, cypress]

bundler-audit:
name: Bundler Audit / Lint
runs-on: ubuntu-20.04
needs: build # I don't need to wait, but I am waiting only because of pipeline organization

container:
image: ruby:3.2.2

steps:
- uses: actions/checkout@v3

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

- name: Update advisory database
run: bundler-audit update

- name: Run bundler-audit
run: bundler-audit
name: Bundler Audit
uses: ./.github/workflows/lint.yml
with:
command: bundle exec bundle-audit check --update
needs: build

eslint:
name: ESLint / Lint
runs-on: ubuntu-20.04
needs: build # I don't need to wait, but I am waiting only because of pipeline organization
name: ESLint
uses: ./.github/workflows/lint.yml
with:
command: yarn eslint
image: gmmcal/gmmcal:cypress
needs: cypress

container:
image: node:18
# container:
# image: node:18

steps:
- uses: actions/checkout@v4
# steps:
# - uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
# - name: Get yarn cache directory path
# id: yarn-cache-dir-path
# run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-gmmcal-
# - uses: actions/cache@v3
# id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
# with:
# path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
# key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-yarn-gmmcal-

- name: Run yarn install
run: yarn install
# - name: Run yarn install
# run: yarn install

- name: Run ESLint - Application
run: yarn eslint
# - name: Run ESLint - Application
# run: yarn eslint

- name: Run ESLint - Tests
run: yarn eslint:tests
# - name: Run ESLint - Tests
# run: yarn eslint:tests
16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ ENV BUNDLE_PATH="/usr/local/bundle"
# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems and node modules
# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config

# Install application gems
COPY Gemfile Gemfile.lock ./
Expand Down Expand Up @@ -94,7 +94,7 @@ ENV RAILS_ENV="test"

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libvips postgresql-client && \
apt-get install --no-install-recommends -y curl libvips postgresql-client git && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand All @@ -120,16 +120,16 @@ WORKDIR /rails

# Copy application code
COPY . .
RUN rm package.json
RUN mv package.ci.json package.json

RUN yarn install

# 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 ["/rails/bin/cypress-entrypoint"]

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

# Start the server by default, this can be overwritten at runtime
CMD ["cypress", "run"]
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ gem 'turbo-rails'
group :development do
# gem 'i18n-debug'
gem 'brakeman'
gem 'bundler-audit'
gem 'listen'
gem 'reek'
gem 'rubocop'
Expand Down
4 changes: 4 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 Down
3 changes: 3 additions & 0 deletions bin/cypress-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

exec "${@}"
51 changes: 51 additions & 0 deletions package.ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "gmmcal.com.br",
"private": true,
"description": "My personal website code, playground and learning lab.",
"version": "3.0.0",
"homepage": "https://www.gmmcal.com.br",
"repository": "https://github.com/gmmcal/gmmcal.com.br",
"bugs": {
"url": "https://github.com/gmmcal/gmmcal.com.br/issues",
"email": "[email protected]"
},
"author": {
"name": "Gustavo Cunha",
"email": "[email protected]",
"url": "https://www.gmmcal.com.br"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/gmmcal/gmmcal.com.br/blob/main/LICENSE"
}
],
"contributors": [
{
"name": "Gustavo Cunha",
"email": "[email protected]",
"url": "https://www.gmmcal.com.br"
}
],
"keywords": [
"ruby",
"rails",
"jest",
"rspec",
"ruby-on-rails",
"cypress",
"end-to-end-testing",
"end-to-end",
"github-actions",
"hakiri",
"heroku",
"ci-cd"
],
"devDependencies": {
"eslint": "*"
},
"scripts": {
"eslint": "eslint --config=.eslintrc.js app/javascript/**/**.js",
"eslint:tests": "eslint --config=.eslintrc.js spec/**/**.js"
}
}

0 comments on commit aa78fe8

Please sign in to comment.