DEV Community

Cover image for A Rails and PostgreSQL setup for GitHub actions (CI)

A Rails and PostgreSQL setup for GitHub actions (CI)

Vincent Voyer on January 10, 2020

Since the release of GitHub actions I always wanted to setup a continuous integration using GitHub actions as described in their documentation. Wh...
Collapse
 
tubbo profile image
Tom Scott

no support for docker-compose

Docker Compose is definitely installed on GitHub actions, not sure what you mean by "no support".

Here's the Workflow that uses make tasks to run the docker-compose commands: github.com/weathermen/soundstorm/b...

And the Makefile, which runs them: github.com/weathermen/soundstorm/b...

Collapse
 
vvo profile image
Vincent Voyer

Thanks for that! I just removed that part. I tried to use it though and ran into issues mostly because my setup is not fully docker-compose based. I use docker-compose only for services, my Rails code runs in the ubuntu container from GitHub.

So the issue I get is this one:

initialize': Permission denied @ dir_initialize - /home/runner/work/project/project/postgres-data (Errno::EACCES)

My docker-compose.yml:

version: "3.7"
services:
  db:
    image: postgres:11.6-alpine
    ports:
      - "54320:5432"
    environment:
      POSTGRES_PASSWORD: turnshift
    volumes:
      - ./postgres-data:/var/lib/postgresql/data

The volume is mounted with a user/permission that is different from the one used when I run the rails test command. I tried to work around that without luck, if you have any idea let me know. From what I can tell I think your whole infra runs in a docker container while me I always run Ruby/Rails locally and only use compose for services (good or bad that's how I do it for now).

Thanks again!

Collapse
 
sabderemane profile image
Sarah Abd

Hi, I've found tricky solution for the manual trigger and also others completed my answer on stack overflow: stackoverflow.com/questions/589331...

Collapse
 
vvo profile image
Vincent Voyer • Edited

Oh wow that's very clever, and I read also the comment on SO from someone saying you could also limit that to the repository owner.

Do you know what it would take to update my current gist to allow for the repository owner, when they star the repo, to trigger a build?

Right now I have:

name: Test

on: [push]

jobs:

what do I need to change? I am new to the syntax :D

Collapse
 
sabderemane profile image
Sarah Abd • Edited

Alright, you can try this :

name: Test

on:
  watch
    types: [started]

jobs:
  build:
    runs-on: ubuntu-latest

    if: github.actor == github.event.repository.owner.login

    steps:
       - name: Checkout repository
         uses: actions/checkout@v2
        #  add more ...

Notice you may have to reindent but I hope it would be fine :)

Thread Thread
 
vvo profile image
Vincent Voyer

Thanks, I guess the last step is on how to combine what you propose with an already in place workflow that gets executed at push time.

For now I have:

name: Test

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
[...]

But if I change that to what you propose then my workflow is no more executed at push time.

Do you know if we can combine both manual trigger trick + usual push testing in a single or a combination of workflows maybe? Let me know!

Thread Thread
 
sabderemane profile image
Sarah Abd

Yes, I set just the beginning but you can adapt it for an existing workflow or a new one.

can combine both manual trigger trick + usual push testing in a single or a combination of workflows

Yes you can !
For your example it will be like that :

on:
  push:
  watch:
    types: [started]

jobs:
  build:
    runs-on: ubuntu-latest

    if: github.actor == github.event.repository.owner.login

    steps:
[...]

I din't try out yet this but I've already tried to setup a workflow with push event and cron, so it should be fine !

Collapse
 
abdellani profile image
Mohamed ABDELLANI • Edited

Hi,

I was working on a very similar article (Actually, I'm not sure that I'll publish it now XD).

In my workflow, I set up two tests. The first one uses Rubocop to do static analysis of the code, and the second one uses RSpec and then generate a report using SimpleCov.
You can check my yaml file here

I also noticed another issue when I was trying to use environment variable to specify the version of the operating system that will be used for the tests.

Great job, thanks for sharing.

Collapse
 
vvo profile image
Vincent Voyer

Hey there, thanks for the comment. Indeed I haven't yet setup multiple steps with dependencies in my setup. I might have to and your example will be very useful, thanks!

Collapse
 
ndrean profile image
NDREAN

Nice posts!. Don't you have in your bag a tuto on how to setup correctly a dockerized React + Rails API using Sidekiq/Redis? As a newbie, developing an app is not so difficult, but deploying it, env variables, the database config.. all these kind of things is a real nightmare.

Collapse
 
vvo profile image
Vincent Voyer

Hey there, sorry I do not have that (also, I stopped my Rails learning and went back to Node.js!).

Good luck though, thanks for your comment

Collapse
 
s4na profile image
s4na

So helpful! Thank you!

Collapse
 
leesmith profile image
Lee Smith 🍻

Awesome guide! Thanks so much!

Collapse
 
unkrass profile image
Unkrass

Do you have any experience with using environment credentials in Github actions? Or should the master.key override the test.key anyway?

Collapse
 
vvo profile image
Vincent Voyer

I have no experience but this post: stackoverflow.com/questions/614445... suggest using a test key and uploading it to GitHub I guess