forked from shibao/cannery
add touchless docker deploys
This commit is contained in:
parent
bde1cff7a4
commit
3dc255b7c2
4
.gitignore
vendored
4
.gitignore
vendored
@ -34,3 +34,7 @@ npm-debug.log
|
|||||||
/priv/static/
|
/priv/static/
|
||||||
|
|
||||||
.elixir_ls/
|
.elixir_ls/
|
||||||
|
|
||||||
|
# direnv
|
||||||
|
.envrc
|
||||||
|
.env
|
53
Dockerfile
Normal file
53
Dockerfile
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
FROM elixir:1.12.2-alpine AS build
|
||||||
|
|
||||||
|
# install build dependencies
|
||||||
|
RUN apk add --no-cache build-base npm git python3
|
||||||
|
|
||||||
|
# prepare build dir
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# install hex + rebar
|
||||||
|
RUN mix local.hex --force && \
|
||||||
|
mix local.rebar --force
|
||||||
|
|
||||||
|
# set build ENV
|
||||||
|
ENV MIX_ENV=prod
|
||||||
|
|
||||||
|
# install mix dependencies
|
||||||
|
COPY mix.exs mix.lock ./
|
||||||
|
COPY config config
|
||||||
|
RUN mix do deps.get, deps.compile
|
||||||
|
|
||||||
|
# build assets
|
||||||
|
COPY assets/package.json assets/package-lock.json ./assets/
|
||||||
|
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
|
||||||
|
|
||||||
|
COPY lib lib
|
||||||
|
COPY priv priv
|
||||||
|
COPY assets assets
|
||||||
|
RUN npm run --prefix ./assets deploy
|
||||||
|
RUN mix phx.digest
|
||||||
|
|
||||||
|
# compile and build release
|
||||||
|
# uncomment COPY if rel/ exists
|
||||||
|
# COPY rel rel
|
||||||
|
RUN mix do compile, release
|
||||||
|
|
||||||
|
# prepare release image
|
||||||
|
FROM alpine:3.9 AS app
|
||||||
|
|
||||||
|
RUN apk upgrade --no-cache && \
|
||||||
|
apk add --no-cache bash openssl libgcc libstdc++ ncurses-libs
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN chown nobody:nobody /app
|
||||||
|
|
||||||
|
USER nobody:nobody
|
||||||
|
|
||||||
|
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/lokal /app
|
||||||
|
COPY --from=build /app/priv/ /app/priv
|
||||||
|
|
||||||
|
ENV HOME=/app
|
||||||
|
|
||||||
|
CMD ["bin/lokal", "start"]
|
438
assets/package-lock.json
generated
438
assets/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
7806
assets/yarn.lock
7806
assets/yarn.lock
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
|||||||
# is restricted to this project.
|
# is restricted to this project.
|
||||||
|
|
||||||
# General application configuration
|
# General application configuration
|
||||||
use Mix.Config
|
import Config
|
||||||
|
|
||||||
config :lokal,
|
config :lokal,
|
||||||
ecto_repos: [Lokal.Repo]
|
ecto_repos: [Lokal.Repo]
|
||||||
@ -28,4 +28,4 @@ config :phoenix, :json_library, Jason
|
|||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{config_env()}.exs"
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
use Mix.Config
|
import Config
|
||||||
|
|
||||||
# Configure your database
|
# Configure your database
|
||||||
config :lokal, Lokal.Repo,
|
config :lokal, Lokal.Repo,
|
||||||
username: "postgres",
|
url: "ecto://postgres:postgres@localhost/lokal_dev",
|
||||||
password: "postgres",
|
|
||||||
database: "lokal_dev",
|
|
||||||
hostname: "localhost",
|
|
||||||
show_sensitive_data_on_connection_error: true,
|
|
||||||
pool_size: 10
|
pool_size: 10
|
||||||
|
|
||||||
# For development, we disable any cache and enable
|
# For development, we disable any cache and enable
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use Mix.Config
|
import Config
|
||||||
|
|
||||||
# For production, don't forget to configure the url host
|
# For production, don't forget to configure the url host
|
||||||
# to something meaningful, Phoenix uses this information
|
# to something meaningful, Phoenix uses this information
|
||||||
@ -10,9 +10,14 @@ use Mix.Config
|
|||||||
# which you should run after static files are built and
|
# which you should run after static files are built and
|
||||||
# before starting your production server.
|
# before starting your production server.
|
||||||
config :lokal, LokalWeb.Endpoint,
|
config :lokal, LokalWeb.Endpoint,
|
||||||
url: [host: "example.com", port: 80],
|
url: [host: "localhost"],
|
||||||
|
http: [port: 4000],
|
||||||
cache_static_manifest: "priv/static/cache_manifest.json"
|
cache_static_manifest: "priv/static/cache_manifest.json"
|
||||||
|
|
||||||
|
config :lokal, Lokal.Repo,
|
||||||
|
url: "ecto://postgres:postgres@localhost/lokal",
|
||||||
|
pool_size: 10
|
||||||
|
|
||||||
# Do not print debug messages in production
|
# Do not print debug messages in production
|
||||||
config :logger, level: :info
|
config :logger, level: :info
|
||||||
|
|
||||||
@ -23,7 +28,7 @@ config :logger, level: :info
|
|||||||
#
|
#
|
||||||
# config :lokal, LokalWeb.Endpoint,
|
# config :lokal, LokalWeb.Endpoint,
|
||||||
# ...
|
# ...
|
||||||
# url: [host: "example.com", port: 443],
|
# url: [host: "localhost", port: 443],
|
||||||
# https: [
|
# https: [
|
||||||
# port: 443,
|
# port: 443,
|
||||||
# cipher_suite: :strong,
|
# cipher_suite: :strong,
|
||||||
@ -49,7 +54,3 @@ config :logger, level: :info
|
|||||||
# force_ssl: [hsts: true]
|
# force_ssl: [hsts: true]
|
||||||
#
|
#
|
||||||
# Check `Plug.SSL` for all available options in `force_ssl`.
|
# Check `Plug.SSL` for all available options in `force_ssl`.
|
||||||
|
|
||||||
# Finally import the config/prod.secret.exs which loads secrets
|
|
||||||
# and configuration from environment variables.
|
|
||||||
import_config "prod.secret.exs"
|
|
||||||
|
@ -2,14 +2,11 @@
|
|||||||
# from environment variables. You can also hardcode secrets,
|
# from environment variables. You can also hardcode secrets,
|
||||||
# although such is generally not recommended and you have to
|
# although such is generally not recommended and you have to
|
||||||
# remember to add this file to your .gitignore.
|
# remember to add this file to your .gitignore.
|
||||||
use Mix.Config
|
import Config
|
||||||
|
|
||||||
database_url =
|
database_url =
|
||||||
System.get_env("DATABASE_URL") ||
|
System.get_env("DATABASE_URL") ||
|
||||||
raise """
|
"ecto://postgres:postgres@lokal-db/lokal"
|
||||||
environment variable DATABASE_URL is missing.
|
|
||||||
For example: ecto://USER:PASS@HOST/DATABASE
|
|
||||||
"""
|
|
||||||
|
|
||||||
config :lokal, Lokal.Repo,
|
config :lokal, Lokal.Repo,
|
||||||
# ssl: true,
|
# ssl: true,
|
||||||
@ -28,14 +25,5 @@ config :lokal, LokalWeb.Endpoint,
|
|||||||
port: String.to_integer(System.get_env("PORT") || "4000"),
|
port: String.to_integer(System.get_env("PORT") || "4000"),
|
||||||
transport_options: [socket_opts: [:inet6]]
|
transport_options: [socket_opts: [:inet6]]
|
||||||
],
|
],
|
||||||
secret_key_base: secret_key_base
|
secret_key_base: secret_key_base,
|
||||||
|
server: true
|
||||||
# ## Using releases (Elixir v1.9+)
|
|
||||||
#
|
|
||||||
# If you are doing OTP releases, you need to instruct Phoenix
|
|
||||||
# to start each relevant endpoint:
|
|
||||||
#
|
|
||||||
# config :lokal, LokalWeb.Endpoint, server: true
|
|
||||||
#
|
|
||||||
# Then you can assemble a release by calling `mix release`.
|
|
||||||
# See `mix help release` for more information.
|
|
@ -1,4 +1,4 @@
|
|||||||
use Mix.Config
|
import Config
|
||||||
|
|
||||||
# Only in tests, remove the complexity from the password hashing algorithm
|
# Only in tests, remove the complexity from the password hashing algorithm
|
||||||
config :bcrypt_elixir, :log_rounds, 1
|
config :bcrypt_elixir, :log_rounds, 1
|
||||||
|
29
docker-compose.yml
Normal file
29
docker-compose.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
lokal:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
container_name: lokal
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: "ecto://postgres:postgres@lokal-db/lokal"
|
||||||
|
# generate a random base64 string 64 characters long, preferably not from a website
|
||||||
|
SECRET_KEY_BASE: "change-me-to-something-random-this-is-really-important-change-it"
|
||||||
|
ports:
|
||||||
|
# do not expose this publically!
|
||||||
|
# always host from behind a reverse proxy, with a properly configured certificate
|
||||||
|
- "4000:4000"
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- lokal-db
|
||||||
|
|
||||||
|
lokal-db:
|
||||||
|
image: postgres:13
|
||||||
|
container_name: lokal-db
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_DB: lokal
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./data:/var/lib/postgresql/data
|
@ -9,6 +9,7 @@ defmodule Lokal.Application do
|
|||||||
children = [
|
children = [
|
||||||
# Start the Ecto repository
|
# Start the Ecto repository
|
||||||
Lokal.Repo,
|
Lokal.Repo,
|
||||||
|
Lokal.Repo.Migrator,
|
||||||
# Start the Telemetry supervisor
|
# Start the Telemetry supervisor
|
||||||
LokalWeb.Telemetry,
|
LokalWeb.Telemetry,
|
||||||
# Start the PubSub system
|
# Start the PubSub system
|
||||||
|
20
lib/lokal/release.ex
Normal file
20
lib/lokal/release.ex
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
defmodule Lokal.Release do
|
||||||
|
@app :lokal
|
||||||
|
|
||||||
|
def rollback(repo, version) do
|
||||||
|
load_app()
|
||||||
|
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp load_app do
|
||||||
|
Application.load(@app)
|
||||||
|
end
|
||||||
|
|
||||||
|
def migrate do
|
||||||
|
load_app()
|
||||||
|
|
||||||
|
for repo <- Application.fetch_env!(@app, :ecto_repos) do
|
||||||
|
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
18
lib/lokal/repo/migrator.ex
Normal file
18
lib/lokal/repo/migrator.ex
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
defmodule Lokal.Repo.Migrator do
|
||||||
|
use GenServer
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
def start_link(_) do
|
||||||
|
GenServer.start_link(__MODULE__, [], [])
|
||||||
|
end
|
||||||
|
|
||||||
|
def init(_) do
|
||||||
|
migrate!()
|
||||||
|
{:ok, nil}
|
||||||
|
end
|
||||||
|
|
||||||
|
def migrate! do
|
||||||
|
path = Application.app_dir(:lokal, "priv/repo/migrations")
|
||||||
|
Ecto.Migrator.run(Lokal.Repo, path, :up, all: true)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user