add touchless docker deploys
This commit is contained in:
		
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -33,4 +33,8 @@ npm-debug.log
 | 
			
		||||
# this depending on your deployment strategy.
 | 
			
		||||
/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.
 | 
			
		||||
 | 
			
		||||
# General application configuration
 | 
			
		||||
use Mix.Config
 | 
			
		||||
import Config
 | 
			
		||||
 | 
			
		||||
config :lokal,
 | 
			
		||||
  ecto_repos: [Lokal.Repo]
 | 
			
		||||
@@ -28,4 +28,4 @@ config :phoenix, :json_library, Jason
 | 
			
		||||
 | 
			
		||||
# Import environment specific config. This must remain at the bottom
 | 
			
		||||
# 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
 | 
			
		||||
config :lokal, Lokal.Repo,
 | 
			
		||||
  username: "postgres",
 | 
			
		||||
  password: "postgres",
 | 
			
		||||
  database: "lokal_dev",
 | 
			
		||||
  hostname: "localhost",
 | 
			
		||||
  show_sensitive_data_on_connection_error: true,
 | 
			
		||||
  url: "ecto://postgres:postgres@localhost/lokal_dev",
 | 
			
		||||
  pool_size: 10
 | 
			
		||||
 | 
			
		||||
# 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
 | 
			
		||||
# to something meaningful, Phoenix uses this information
 | 
			
		||||
@@ -10,8 +10,13 @@ use Mix.Config
 | 
			
		||||
# which you should run after static files are built and
 | 
			
		||||
# before starting your production server.
 | 
			
		||||
config :lokal, LokalWeb.Endpoint,
 | 
			
		||||
  url: [host: "example.com", port: 80],
 | 
			
		||||
  url: [host: "localhost"],
 | 
			
		||||
  http: [port: 4000],
 | 
			
		||||
  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
 | 
			
		||||
config :logger, level: :info
 | 
			
		||||
@@ -23,7 +28,7 @@ config :logger, level: :info
 | 
			
		||||
#
 | 
			
		||||
#     config :lokal, LokalWeb.Endpoint,
 | 
			
		||||
#       ...
 | 
			
		||||
#       url: [host: "example.com", port: 443],
 | 
			
		||||
#       url: [host: "localhost", port: 443],
 | 
			
		||||
#       https: [
 | 
			
		||||
#         port: 443,
 | 
			
		||||
#         cipher_suite: :strong,
 | 
			
		||||
@@ -49,7 +54,3 @@ config :logger, level: :info
 | 
			
		||||
#       force_ssl: [hsts: true]
 | 
			
		||||
#
 | 
			
		||||
# 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,
 | 
			
		||||
# although such is generally not recommended and you have to
 | 
			
		||||
# remember to add this file to your .gitignore.
 | 
			
		||||
use Mix.Config
 | 
			
		||||
import Config
 | 
			
		||||
 | 
			
		||||
database_url =
 | 
			
		||||
  System.get_env("DATABASE_URL") ||
 | 
			
		||||
    raise """
 | 
			
		||||
    environment variable DATABASE_URL is missing.
 | 
			
		||||
    For example: ecto://USER:PASS@HOST/DATABASE
 | 
			
		||||
    """
 | 
			
		||||
    "ecto://postgres:postgres@lokal-db/lokal"
 | 
			
		||||
 | 
			
		||||
config :lokal, Lokal.Repo,
 | 
			
		||||
  # ssl: true,
 | 
			
		||||
@@ -28,14 +25,5 @@ config :lokal, LokalWeb.Endpoint,
 | 
			
		||||
    port: String.to_integer(System.get_env("PORT") || "4000"),
 | 
			
		||||
    transport_options: [socket_opts: [:inet6]]
 | 
			
		||||
  ],
 | 
			
		||||
  secret_key_base: secret_key_base
 | 
			
		||||
 | 
			
		||||
# ## 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.
 | 
			
		||||
  secret_key_base: secret_key_base,
 | 
			
		||||
  server: true
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
use Mix.Config
 | 
			
		||||
import Config
 | 
			
		||||
 | 
			
		||||
# Only in tests, remove the complexity from the password hashing algorithm
 | 
			
		||||
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 = [
 | 
			
		||||
      # Start the Ecto repository
 | 
			
		||||
      Lokal.Repo,
 | 
			
		||||
      Lokal.Repo.Migrator,
 | 
			
		||||
      # Start the Telemetry supervisor
 | 
			
		||||
      LokalWeb.Telemetry,
 | 
			
		||||
      # 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
 | 
			
		||||
		Reference in New Issue
	
	Block a user