mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 19:57:52 +01:00
Add .env file for docker-compose
This commit is contained in:
6
.env-example
Normal file
6
.env-example
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
ENVIRONMENT=development
|
||||||
|
|
||||||
|
POSTGRES_USER=yourusernamehere
|
||||||
|
POSTGRES_PASSWORD=yourpasswordhere
|
||||||
|
|
||||||
|
APP_NAME="You App Name Here"
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,6 +4,9 @@
|
|||||||
# or operating system, you probably want to add a global ignore instead:
|
# or operating system, you probably want to add a global ignore instead:
|
||||||
# git config --global core.excludesfile '~/.gitignore_global'
|
# git config --global core.excludesfile '~/.gitignore_global'
|
||||||
|
|
||||||
|
# Ignore the actual contents of .env
|
||||||
|
.env
|
||||||
|
|
||||||
# Ignore bundler config.
|
# Ignore bundler config.
|
||||||
/.bundle
|
/.bundle
|
||||||
|
|
||||||
|
|||||||
@@ -29,5 +29,4 @@ ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
|||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start the main process.
|
# No default CMD is provided in Dockerfile
|
||||||
CMD ["foreman", "start", "-p", "3000"]
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<nav class="navbar navbar-expand-md navbar-light">
|
<nav class="navbar navbar-expand-md navbar-light">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<%= link_to 'Astuto', root_path, class: 'navbar-brand' %>
|
<%= link_to Rails.application.name, root_path, class: 'navbar-brand' %>
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Astuto</title>
|
<title><%= Rails.application.name %></title>
|
||||||
<%= csrf_meta_tags %>
|
<%= csrf_meta_tags %>
|
||||||
<%= csp_meta_tag %>
|
<%= csp_meta_tag %>
|
||||||
|
|
||||||
|
|||||||
19
check-env.sh
Normal file
19
check-env.sh
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e # Abort on error
|
||||||
|
|
||||||
|
function check_env_vars () {
|
||||||
|
for name; do
|
||||||
|
: ${!name:?$name must not be empty}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ ! -f .env ]; then
|
||||||
|
echo 'A .env file must be present.'
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! check_env_vars "ENVIRONMENT" "APP_NAME" "POSTGRES_USER" "POSTGRES_PASSWORD"; then
|
||||||
|
echo 'Some variables are not set in .env, please refer to script/check-env.sh for the list'
|
||||||
|
exit 4
|
||||||
|
fi
|
||||||
@@ -15,5 +15,9 @@ module App
|
|||||||
# Application configuration can go into files in config/initializers
|
# Application configuration can go into files in config/initializers
|
||||||
# -- all .rb files in that directory are automatically loaded after loading
|
# -- all .rb files in that directory are automatically loaded after loading
|
||||||
# the framework and any gems in your application.
|
# the framework and any gems in your application.
|
||||||
|
|
||||||
|
def name
|
||||||
|
ENV["APP_NAME"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ default: &default
|
|||||||
encoding: unicode
|
encoding: unicode
|
||||||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
||||||
host: db
|
host: db
|
||||||
username: postgres
|
username: <%= ENV['POSTGRES_USER'] %>
|
||||||
password:
|
password: <%= ENV['POSTGRES_PASSWORD'] %>
|
||||||
|
|
||||||
development:
|
development:
|
||||||
<<: *default
|
<<: *default
|
||||||
@@ -82,5 +82,3 @@ test:
|
|||||||
production:
|
production:
|
||||||
<<: *default
|
<<: *default
|
||||||
database: app_production
|
database: app_production
|
||||||
username: app
|
|
||||||
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
|
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ version: '3'
|
|||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
image: postgres
|
image: postgres
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER
|
||||||
|
- POSTGRES_PASSWORD
|
||||||
volumes:
|
volumes:
|
||||||
- ./tmp/db:/var/lib/postgresql/data
|
- ./tmp/db:/var/lib/postgresql/data
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
environment:
|
environment:
|
||||||
- UPDATE=0
|
- UPDATE=0
|
||||||
|
- ENVIRONMENT
|
||||||
|
- APP_NAME
|
||||||
|
- POSTGRES_USER
|
||||||
|
- POSTGRES_PASSWORD
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file serves 3 use cases:
|
||||||
|
# 1: if the env variable UPDATE is 1, the database is prepared
|
||||||
|
# 2: if a command was supplied, it is executed
|
||||||
|
# 3: otherwise, check env variable ENVIRONMENT and launch server
|
||||||
|
|
||||||
# Exit immediately if a command exits with a non-zero status.
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Check environment variables
|
||||||
|
/bin/bash ./check-env.sh
|
||||||
|
|
||||||
|
# Remove a potentially pre-existing server.pid for Rails.
|
||||||
|
rm -f /app/tmp/pids/server.pid
|
||||||
|
|
||||||
|
# Use case 1
|
||||||
if [ "$UPDATE" = 1 ]; then
|
if [ "$UPDATE" = 1 ]; then
|
||||||
# Create database, load schema, run migrations and seed data in an idempotent way.
|
# Create database, load schema, run migrations and seed data in an idempotent way.
|
||||||
echo "Preparing database..."
|
echo "Preparing database..."
|
||||||
@@ -17,8 +29,19 @@ if [ "$UPDATE" = 1 ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove a potentially pre-existing server.pid for Rails.
|
# Use case 2
|
||||||
rm -f /app/tmp/pids/server.pid
|
if [ ! $# -eq 0 ]; then
|
||||||
|
exec "$@"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Then exec the container's main process (what's set as CMD in the Dockerfile).
|
# Use case 3
|
||||||
exec "$@"
|
echo "Environment is: $ENVIRONMENT"
|
||||||
|
if [ $ENVIRONMENT == "development" ]; then
|
||||||
|
# Launch Rails server and webpack-dev-server using Foreman
|
||||||
|
foreman start -p 3000
|
||||||
|
else # production
|
||||||
|
# Compile assets with Webpack and then launch Rails server
|
||||||
|
./bin/webpack
|
||||||
|
rails server -e production
|
||||||
|
fi
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
|
set -e
|
||||||
|
|
||||||
echo "Starting Astuto..."
|
echo "Starting Astuto..."
|
||||||
|
|
||||||
docker-compose up "$@"
|
docker-compose up "$@"
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
|
set -e
|
||||||
|
|
||||||
/bin/bash script/docker-update.sh
|
/bin/bash script/docker-update.sh
|
||||||
/bin/bash script/docker-run.sh
|
/bin/bash script/docker-run.sh
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
|
set -e
|
||||||
|
|
||||||
echo "Starting update..."
|
echo "Starting update..."
|
||||||
echo "-> Docker image will be rebuilt if necessary"
|
echo "-> Docker image will be rebuilt if necessary"
|
||||||
echo "-> Database schema will be updated if necessary"
|
echo "-> Database schema will be updated if necessary"
|
||||||
|
|||||||
Reference in New Issue
Block a user