Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable PullPreview action (pullpreview.com) #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions .env.pullpreview
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SNS_CONFIGURATION_SET=metrics

SES_ADDRESS=email-smtp.us-east-1.amazonaws.com
SES_USER_NAME=
SES_PASSWORD=

AWS_ACCESS_KEY_ID=abcd
AWS_SECRET_ACCESS_KEY=efgh

AWS_S3_BUCKET=bucket
AWS_S3_REGION=us-east-1

FULLCONTACT_TOKEN=

[email protected]
ADMIN_PASSWORD=password
24 changes: 24 additions & 0 deletions .github/workflows/pullpreview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: PullPreview
on:
push:
pull_request:
types: [labeled, unlabeled, closed]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: pullpreview/action@v3
with:
admins: michelson
always_on: master
default_port: 443
instance_type: medium_2_0
compose_files: docker-compose.pullpreview.yml
env:
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}"
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
AWS_REGION: "us-east-1"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ stats.json
.DS_Store
app/javascript/old-src
.envrc

*.swp
16 changes: 7 additions & 9 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@

domain = ENV['HOST'] || 'http://localhost:3000'

app = App.create(
name: 'test app',
domain_url: domain
)
if App.none?
app = App.create(
name: 'test app',
domain_url: domain
)

Doorkeeper::Application.create(
name: "authapp",
#redirect_uri: "#{domain}/callback"
)

AppPackagesCatalog.import unless Rails.env.test?
AppPackagesCatalog.import unless Rails.env.test?
end
93 changes: 93 additions & 0 deletions docker-compose.pullpreview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
version: '2.4'

x-app: &app
build:
context: .
dockerfile: ./Dockerfile
args:
APP_ENV: production
RUBY_VERSION: '2.6.5'
PG_MAJOR: '11'
NODE_MAJOR: '10'
YARN_VERSION: '1.13.0'
BUNDLER_VERSION: '2.0.2'
environment: &env
NODE_ENV: production
RAILS_ENV: ${RAILS_ENV:-production}
SECRET_KEY_BASE: mysecretchangeme
HOST: "${PULLPREVIEW_URL:-http://localhost:3000}"
ASSET_HOST: "${PULLPREVIEW_URL:-http://localhost:3000}"
RAILS_SERVE_STATIC_FILES: "true"
RAILS_LOG_TO_STDOUT: "true"
SKIP_SUBDOMAIN_CHECK: "true"

x-backend: &backend
<<: *app
env_file: .env.pullpreview
environment:
<<: *env
REDIS_URL: redis://redis:6379/
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
WEB_CONCURRENCY: 2
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy

services:
seeder:
<<: *backend
command: bundle exec rake db:migrate db:seed admin_generator
restart: on-failure

rails:
<<: *backend
command: bundle exec rails server -b 0.0.0.0
ports:
- '3000'

sidekiq:
<<: *backend
command: bundle exec sidekiq -C config/sidekiq.yml

postgres:
image: postgres:11.1
volumes:
- postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432
healthcheck:
test: pg_isready -U postgres -h 127.0.0.1
interval: 5s

redis:
image: redis:3.2-alpine
volumes:
- redis:/data
ports:
- 6379
healthcheck:
test: redis-cli ping
interval: 1s
timeout: 3s
retries: 30

proxy:
image: caddy:2-alpine
command: "caddy reverse-proxy --from '${PULLPREVIEW_URL}' --to rails:3000"
restart: unless-stopped
volumes:
- proxy:/data/caddy
depends_on:
- rails
ports:
- "443:443"

volumes:
postgres:
redis:
proxy:
1 change: 1 addition & 0 deletions lib/subdomain_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def self.matches?(request)

class SubdomainOrDomain
def self.matches?(request)
return false if ENV.fetch("SKIP_SUBDOMAIN_CHECK", "false") == "true"
if request.subdomain.present? && !APP_SUBDOMAINS.include?(request.subdomain)
true
# elsif request.host != 'www.#{DOMAIN}'
Expand Down
12 changes: 7 additions & 5 deletions lib/tasks/admin_generator.rake
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# desc "Explaining what the task does"
task admin_generator: :environment do
app = App.first
app.add_admin(Agent.create(
email: ENV['ADMIN_EMAIL'],
password: ENV['ADMIN_PASSWORD']
))
end
if app.app_users.find_by(email: ENV['ADMIN_EMAIL']).nil?
app.add_admin(Agent.create(
email: ENV['ADMIN_EMAIL'],
password: ENV['ADMIN_PASSWORD']
))
end
end