Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: GitHub Actions Demo
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
161 changes: 56 additions & 105 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,114 +1,65 @@
# This is a basic workflow to help you get started with Actions
name: Rails
on: push

name: CI-CD

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains multiple jobs
build_test:
# The type of runner that the job will run on
verify:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
services:
postgres:
image: postgres:11
env:
POSTGRES_USER: rails_github_actions
POSTGRES_DB: rails_github_actions_test
POSTGRES_PASSWORD: postgres
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

# Runs a single command using the runners shell
- name: Setup Node.js
uses: actions/setup-node@master
with:
node-version: ${{ matrix.node-version }}

# Install app dependencies
- name: Install Dependencies
run: |
cd node
npm ci
# Build and test the app
- name: Build and test
run: |
cd node
npm run build:prod
npm run test
push_to_docker_hub:
runs-on: ubuntu-latest
# Build Docker image and push to Docker Hub only if the app build and test is successfull
needs: [build_test]
# if you need redis
# redis:
# image: redis
# ports:
# - 6379:6379
# options: --entrypoint redis-server

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
- uses: actions/checkout@v1
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
ruby-version: 2.6.x
- name: Set up Node
uses: actions/setup-node@v1
with:
# This path is totally independant from the 'file' directve below
context: ./node
# This path is totally independant from the 'context' directive above
file: ./node/Dockerfile.prod
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/node-docker-deploy:latest
# I left this job here only for reference. As in Dockerfile I use the
# distroless image (i.e. it doesn't have shell), this step is impossible
# to execute
#
# - name: Run the image in a container
# uses: addnab/docker-run-action@v3
# with:
# image: ${{ secrets.DOCKERHUB_USERNAME }}/node-docker-deploy:latest
# run: |
# echo "running the docker image"
# echo "Testing the nodejs app endpoints"
# echo ${{ steps.docker_build.outputs.digest }}

deploy:
runs-on: ubuntu-latest
needs: [push_to_docker_hub]

steps:
- name: Deploy to VPS
uses: appleboy/ssh-action@master
# TODO: add env vars as secrets on GitHub
with:
# VPS IP
host: ${{ secrets.VPS_SSH_HOST }}
# VPS username
username: ${{ secrets.VPS_SSH_USERNAME }}
# SSH key (copy it from your local machine)
key: ${{ secrets.VPS_SSH_SECRET }}
# SSH port
port: ${{ secrets.VPS_SSH_PORT }}
script: |
echo "Pull new image"
docker-compose -f /home/${{ secrets.VPS_SSH_USERNAME }}/node-docker-deploy/docker-compose.yml pull
echo "Restart the container"
docker-compose -f /home/${{ secrets.VPS_SSH_USERNAME }}/node-docker-deploy/docker-compose.yml up --force-recreate --build --no-deps -d
echo "Delete old image"
docker image prune -f
node-version: 10.13.0
- name: Install dependencies
run: |
sudo apt-get -yqq install libpq-dev build-essential libcurl4-openssl-dev
gem install bundler
bundle install --jobs 4 --retry 3
yarn install
- name: Setup test database
env:
RAILS_ENV: test
PGHOST: localhost
POSTGRES_DB: rails_github_actions_test
POSTGRES_USER: rails_github_actions
POSTGRES_PASSWORD: postgres
run: |
cp config/database.ci.yml config/database.yml
rake db:create db:migrate

- name: Run tests
env:
PGHOST: localhost
POSTGRES_DB: rails_github_actions_test
POSTGRES_USER: rails_github_actions
POSTGRES_PASSWORD: postgres
PGPORT: ${{ job.services.postgres.ports[5432] }}
RAILS_ENV: test
run: rspec
3 changes: 3 additions & 0 deletions api/backend/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ default: &default
adapter: postgresql
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password: password
host: db

development:
<<: *default
Expand Down
2 changes: 1 addition & 1 deletion mobile/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "5.3.1"
version: "6.1.0"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.1"