Fakultas Ilmu Komputer UI

Commit 1da42d1a authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Merge branch 'deploy-runtime' into 'master'

Deploy runtime

See merge request !1
parents 450ebd87 99362456
# .dockerignore
.git
Dockerfile
# Mix artifacts
_build
deps
*.ez
# Generate on crash by the VM
erl_crash.dump
# Static artifacts
node_modules
\ No newline at end of file
# File: docker_phx/Dockerfile
FROM elixir:1.11-alpine as build
# install build dependencies
RUN apk add --update --no-cache build-base npm git py-pip
RUN mkdir /app
WORKDIR /app
# install Hex + Rebar
RUN mix do local.hex --force, local.rebar --force
# set build ENV
ENV MIX_ENV=prod
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get --only $MIX_ENV
RUN mix deps.compile
# build assets
# COPY assets assets
# RUN cd assets && npm install && npm run deploy
# RUN mix phx.digest
# build project
COPY priv priv
COPY lib lib
RUN mix compile
# build release
# at this point we should copy the rel directory but
# we are not using it so we can omit it
# COPY rel rel
RUN mix release
# prepare release image
FROM alpine:3.13 AS app
# install runtime dependencies
RUN apk add --update bash openssl postgresql-client
EXPOSE 4000
ENV MIX_ENV=prod
# prepare app directory
RUN mkdir /app
WORKDIR /app
# copy release to app container
COPY --from=build /app/_build/prod/rel/diskuy .
COPY entrypoint.sh .
RUN chown -R nobody: /app
USER nobody
ENV HOME=/app
CMD ["bash", "/app/entrypoint.sh"]
\ No newline at end of file
SECRET_KEY_BASE=REALLY_LONG_SECRET
DATABASE_HOST=db
DATABASE_URL=ecto://postgres:postgres@db/postgres
PORT=4000
HOSTNAME=localhost
POSTGRES_PASSWORD=postgres
LANG=en_US.UTF-8s
\ No newline at end of file
......@@ -10,8 +10,8 @@ use Mix.Config
# which you should run after static files are built and
# before starting your production server.
config :diskuy, DiskuyWeb.Endpoint,
url: [host: "example.com", port: 80],
cache_static_manifest: "priv/static/cache_manifest.json"
url: [host: "localhost", port: 4000]
# cache_static_manifest: "priv/static/cache_manifest.json"
# Do not print debug messages in production
config :logger, level: :info
......@@ -52,4 +52,4 @@ config :logger, level: :info
# Finally import the config/prod.secret.exs which loads secrets
# and configuration from environment variables.
import_config "prod.secret.exs"
# import_config "prod.secret.exs"
......@@ -2,7 +2,7 @@
# 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") ||
......@@ -35,7 +35,7 @@ config :diskuy, DiskuyWeb.Endpoint,
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
#
# config :diskuy, DiskuyWeb.Endpoint, server: true
config :diskuy, DiskuyWeb.Endpoint, server: true
#
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.
# File docker_phx/docker-compose.yml
version: "3.5"
networks:
webnet:
driver: overlay
attachable: true # Needed in order to run custom commands in the container
services:
app:
image: docker_diskuy:0.1.0
ports:
- "80:4000"
env_file:
- config/docker.env
depends_on:
- db
deploy:
replicas: 1
restart_policy:
condition: on-failure
networks:
- webnet
db:
image: postgres:12-alpine
deploy:
replicas: 1
placement:
constraints: [node.role == manager]
restart_policy:
condition: on-failure
volumes:
- "./volumes/postgres:/var/lib/postgresql/data"
ports:
- "4545:5432"
env_file:
- config/docker.env
networks:
- webnet
\ No newline at end of file
# File: docker_phx/entrypoint.sh
#!/bin/bash
# docker entrypoint script.
# assign a default for the database_user
# DB_USER=${DATABASE_USER:-postgres}
# # wait until Postgres is ready
# while ! pg_isready -q -h $DATABASE_HOST -p 5432 -U $DB_USER
# do
# echo "$(date) - waiting for database to start"
# sleep 2
# done
bin="/app/bin/diskuy"
eval "$bin eval \"Diskuy.Release.migrate\""
# start the elixir application
exec "$bin" "start"
\ No newline at end of file
defmodule Diskuy.Release do
@app :diskuy
def migrate do
load_app()
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp load_app do
Application.load(@app)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment