Skip to content

Migrate to Docker/ECS deployment #6

Migrate to Docker/ECS deployment

Migrate to Docker/ECS deployment #6

Workflow file for this run

name: Deploy
on:
push:
branches: [ develop, main ]
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'staging'
type: choice
options:
- staging
- production
env:
RAILS_ENV: production
permissions:
id-token: write # Required for AWS OIDC
contents: read
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: otb_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: true
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client imagemagick libpq-dev gdal-bin libgdal-dev
- name: Create directories
run: |
sudo mkdir -p /data/tmp
sudo chmod 777 /data/tmp
mkdir -p public/storage/tmp
- name: Set up database
run: |
export DB_ADAPTER=postgresql
until pg_isready -h localhost -p 5432 -U postgres; do sleep 2; done
bundle exec rake db:create RAILS_ENV=test DB_ADAPTER=postgresql
bundle exec rake db:schema:load RAILS_ENV=test DB_ADAPTER=postgresql
- name: Run tests
run: |
DB_ADAPTER=postgresql bundle exec rspec --format progress
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: us-east-1
role-session-name: GitHub-OIDC-OTB
- name: Deploy to ECS
env:
AWS_ECR: ${{ secrets.AWS_ECR }}
AWS_ECS_CLUSTER_DEV: ${{ secrets.AWS_ECS_CLUSTER_DEV }}
AWS_ECS_CLUSTER_PROD: ${{ secrets.AWS_ECS_CLUSTER_PROD }}
AWS_ECS_SERVICE_DEV: ${{ secrets.AWS_ECS_SERVICE_DEV }}
AWS_ECS_SERVICE_PROD: ${{ secrets.AWS_ECS_SERVICE_PROD }}
AWS_REGION: ${{ secrets.AWS_REGION }}
BRANCH: ${{ github.ref_name }}
run: |
chmod +x build.sh
./build.sh
- name: Notify deployment status
if: always()
run: |
branch="${{ github.ref_name }}"
environment=$([ "$branch" == "main" ] && echo "production" || echo "staging")
if [[ "${{ job.status }}" == "success" ]]; then
echo "Successfully deployed to $environment via ECS"
else
echo "Deployment to $environment failed"
fi