Add GitHub Actions (#211)

* Add 'run-tests' action to run specs
* Add 'push-to-registry' action to push image to Docker Hub
This commit is contained in:
Riccardo Graziosi
2023-04-16 15:53:05 +02:00
committed by GitHub
parent 1e6eb17af5
commit 60b0919ce6
9 changed files with 170 additions and 68 deletions

38
.github/workflows/push-to-registry.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
# Build production image and push to Docker Hub
name: Push to registry
on:
push:
branches:
- 'main'
tags:
- '**'
jobs:
push-to-registry:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
target: prod
build-args: |
ENVIRONMENT=production
push: true
tags: |
riggraz/astuto:latest
riggraz/astuto:${{ github.sha }}
riggraz/astuto:${{ github.ref_type == 'tag' && github.ref_name || 'latest'}}

48
.github/workflows/run-tests.yml vendored Normal file
View File

@@ -0,0 +1,48 @@
# Build production image and run tests on it
name: Run tests
on:
workflow_dispatch:
pull_request:
paths:
- '**'
jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Build Docker production image
run: docker compose -f docker-compose.yml -f docker-compose-prod.yml build --build-arg ENVIRONMENT=production
- name: Run Docker containers
run: docker compose -f docker-compose.yml -f docker-compose-prod.yml up --detach
- name: Install required packages
run: |
docker compose exec web apt-get update
docker compose exec web apt-get install -y --no-install-recommends apt-utils
docker compose exec web apt-get install -y build-essential wget libpq-dev
- name: Install RSpec and required gems
run: |
docker compose exec web bundle config set --local without development
docker compose exec web bundle config set deployment false --local
docker compose exec web bundle install
- name: Install Google Chrome
run: |
docker compose exec web wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
docker compose exec web dpkg -i google-chrome-stable_current_amd64.deb || true
docker compose exec web apt-get -fy install
- name: Prepare assets for test environment
run: docker compose exec web cp -r public/packs/ public/packs-test/
- name: Run tests
run: docker compose exec web bundle exec rspec