Skip to content

Commit

Permalink
automations
Browse files Browse the repository at this point in the history
  • Loading branch information
baldarn committed Aug 20, 2024
1 parent dbf86d1 commit 70d6678
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 118 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: ci
on:
push:
branches: ["main"]
tags:
- "*"
pull_request:
branches: ["main"]
jobs:
tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16.4-alpine
ports:
- "5432:5432"
env:
POSTGRES_DB: opengas_test
POSTGRES_USER: opengas
POSTGRES_PASSWORD: opengas
env:
RAILS_ENV: test
DATABASE_URL: "postgres://opengas:opengas@localhost:5432/opengas_test"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
bundler-cache: true
- name: Set up database schema
run: bin/rails db:schema:load
- name: Run tests
run: bin/rails test

system-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16.4-alpine
ports:
- "5432:5432"
env:
POSTGRES_DB: opengas_test
POSTGRES_USER: opengas
POSTGRES_PASSWORD: opengas
env:
RAILS_ENV: test
DATABASE_URL: "postgres://opengas:opengas@localhost:5432/opengas_test"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
bundler-cache: true
- name: Set up database schema
run: bin/rails db:schema:load
- name: Run tests
run: bin/rails test:system

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
bundler-cache: true
- name: Security audit dependencies
run: bundle exec bundler-audit --update
- name: Security audit
run: bundle exec bundle audit
- name: Security audit application code
run: bin/brakeman -q -w2
- name: Lint Ruby files
run: bin/rubocop --parallel

build:
needs: [tests, system-tests, lint]
if: ${{ github.ref_type == 'tag' }}
runs-on: ubuntu-latest

env:
DOCKER_BUILDKIT: 1

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
bundler-cache: true
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: baldarn
password: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
push: true
build-args: |
APP_VERSION=${{ github.ref_name }}
labels: |
"service=open-gas"
tags: |
baldarn/open-gas:latest
baldarn/open-gas:${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max

deploy:
needs: [build]
runs-on: ubuntu-latest
concurrency:
group: deploy
cancel-in-progress: true

env:
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
bundler-cache: true
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Deploy command
run: bundle exec kamal deploy --skip-push --version ${{ github.ref_name }}
29 changes: 29 additions & 0 deletions .github/workflows/kamal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Kamal Command

on:
workflow_dispatch:
inputs:
command:
description: "Kamal command to run"
default: "kamal app details"

jobs:
Command:
runs-on: ubuntu-latest

env:
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
- name: Run KAMAL command
run: ${{ github.event.inputs.command }}
56 changes: 0 additions & 56 deletions .github/workflows/rubyonrails.yml

This file was deleted.

1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ AllCops:
Exclude:
- bin/*
- db/schema.rb
- vendor/**/*

Style/Documentation:
Enabled: false
Expand Down
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.4
FROM ruby:$RUBY_VERSION-slim as base
ARG APP_VERSION=undefined
FROM ruby:$RUBY_VERSION-slim AS base

# Rails app lives here
WORKDIR /rails
Expand All @@ -11,7 +12,8 @@ WORKDIR /rails
ENV RAILS_ENV="production" \

Check warning on line 12 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$APP_VERSION' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"
BUNDLE_WITHOUT="development" \
APP_VERSION=${APP_VERSION}

# Throw-away build stage to reduce size of final image
FROM --platform=$TARGETPLATFORM base as build

Check warning on line 19 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 19 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/
Expand All @@ -28,9 +30,6 @@ RUN bundle install && \
# Copy application code
COPY . .

# Set app version from git
ENV APP_VERSION="$(git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD)"

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ gem 'useragent', github: 'basecamp/useragent'
group :development, :test do
gem 'debug'
gem 'faker', require: false
gem 'rubocop', '~> 1.65', require: false
gem 'rubocop-capybara', require: false
gem 'rubocop-rails', require: false
end
Expand Down
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ GEM
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.25.1)
parallel (1.26.3)
parser (3.3.3.0)
ast (~> 2.4.1)
racc
Expand Down Expand Up @@ -332,13 +332,13 @@ GEM
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rubocop (1.64.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
Expand Down Expand Up @@ -476,6 +476,7 @@ DEPENDENCIES
redcarpet (~> 3.6)
rouge (~> 4.2)
rqrcode
rubocop (~> 1.65)
rubocop-capybara
rubocop-rails
sassc-rails
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![ci](https://github.com/baldarn/open-GAS/actions/workflows/ci.yml/badge.svg)](https://github.com/baldarn/open-GAS/actions/workflows/ci.yml)

# Open GAS
### The open source software for sports associations

Expand Down
25 changes: 14 additions & 11 deletions app/views/application/_footer.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@

<div class="container-fluid">
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
<div class="col-4 d-flex align-items-center">
<a href="https://github.com/baldarn/open-GAS">
<%= image_tag "github.svg", aria: { hidden: true }, size: 45, class: "bi d-block mx-auto mb-1" %>
</div>
<div class="nav col-md-4 justify-content-end list-unstyled d-flex">
<a href="https://www.iubenda.com/privacy-policy/35860933" class="iubenda-white iubenda-noiframe iubenda-embed iubenda-noiframe " title="Privacy Policy ">Privacy Policy</a><script type="text/javascript">
(function (w,d) {var loader = function () {var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0]; s.src="https://cdn.iubenda.com/iubenda.js"; tag.parentNode.insertBefore(s,tag);}; if(w.addEventListener){w.addEventListener("load", loader, false);}else if(w.attachEvent){w.attachEvent("onload", loader);}else{w.onload = loader;}})(window, document);
</script>
<a href="https://www.iubenda.com/privacy-policy/35860933/cookie-policy" class="iubenda-white iubenda-noiframe iubenda-embed iubenda-noiframe " title="Cookie Policy ">Cookie Policy</a><script type="text/javascript">
(function (w,d) {var loader = function () {var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0]; s.src="https://cdn.iubenda.com/iubenda.js"; tag.parentNode.insertBefore(s,tag);}; if(w.addEventListener){w.addEventListener("load", loader, false);}else if(w.attachEvent){w.attachEvent("onload", loader);}else{w.onload = loader;}})(window, document);
</script>
</div>
</a>
<% if ENV['APP_VERSION'].present? %>
<span style='margin-left: 10px;'>v<%= ENV['APP_VERSION'] %></span>
<% end %>
</div>
</footer>
<div class="nav col-md-4 justify-content-end list-unstyled d-flex">
<a href="https://www.iubenda.com/privacy-policy/35860933" class="iubenda-white iubenda-noiframe iubenda-embed iubenda-noiframe " title="Privacy Policy ">Privacy Policy</a><script type="text/javascript">
(function (w,d) {var loader = function () {var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0]; s.src="https://cdn.iubenda.com/iubenda.js"; tag.parentNode.insertBefore(s,tag);}; if(w.addEventListener){w.addEventListener("load", loader, false);}else if(w.attachEvent){w.attachEvent("onload", loader);}else{w.onload = loader;}})(window, document);
</script>
<a href="https://www.iubenda.com/privacy-policy/35860933/cookie-policy" class="iubenda-white iubenda-noiframe iubenda-embed iubenda-noiframe " title="Cookie Policy ">Cookie Policy</a><script type="text/javascript">
(function (w,d) {var loader = function () {var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0]; s.src="https://cdn.iubenda.com/iubenda.js"; tag.parentNode.insertBefore(s,tag);}; if(w.addEventListener){w.addEventListener("load", loader, false);}else if(w.attachEvent){w.attachEvent("onload", loader);}else{w.onload = loader;}})(window, document);
</script>
</div>
</div>
</footer>
</div>
39 changes: 0 additions & 39 deletions config/deploy.staging.yml

This file was deleted.

4 changes: 0 additions & 4 deletions config/initializers/version.rb

This file was deleted.

0 comments on commit 70d6678

Please sign in to comment.