Skip to content

Commit 3b8ecae

Browse files
committed
chore: bump to 1.0.1
1 parent e8bb2d3 commit 3b8ecae

File tree

8 files changed

+135
-30
lines changed

8 files changed

+135
-30
lines changed

.dockerignore

+42-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
1-
# Ignore version control files
1+
# This file excludes paths from the Docker build context.
2+
#
3+
# By default, Docker's build context includes all files (and folders) in the
4+
# current directory. Even if a file isn't copied into the container it is still sent to
5+
# the Docker daemon.
6+
#
7+
# There are multiple reasons to exclude files from the build context:
8+
#
9+
# 1. Prevent nested folders from being copied into the container (ex: exclude
10+
# /assets/node_modules when copying /assets)
11+
# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc)
12+
# 3. Avoid sending files containing sensitive information
13+
#
14+
# More information on using .dockerignore is available here:
15+
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
16+
17+
.dockerignore
18+
19+
# Ignore git, but keep git HEAD and refs to access current commit hash if needed:
20+
#
21+
# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat
22+
# d0b8727759e1e0e7aa3d41707d12376e373d5ecc
223
.git
3-
.gitignore
24+
!.git/HEAD
25+
!.git/refs
26+
27+
# Common development/test artifacts
28+
/cover/
29+
/doc/
30+
/test/
31+
/tmp/
32+
.elixir_ls
33+
34+
# Mix artifacts
35+
/_build/
36+
/deps/
37+
*.ez
438

5-
# Ignore build artifacts
6-
_build
7-
deps
39+
# Generated on crash by the VM
40+
erl_crash.dump
841

9-
# Ignore editor files
10-
*.swp
11-
*.swo
12-
*.swn
13-
*.swm
14-
*.swl
15-
*.swk
16-
*.swc
17-
*.swo
18-
*.beam
19-
*.iml
20-
.idea
21-
.vscode
22-
.editorconfig
42+
# Static artifacts - These should be fetched and built inside the Docker image
43+
/assets/node_modules/
44+
/priv/static/assets/
45+
/priv/static/cache_manifest.json

Dockerfile

+51-10
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,74 @@
1+
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
2+
# instead of Alpine to avoid DNS resolution issues in production.
3+
#
4+
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
5+
# https://hub.docker.com/_/ubuntu?tab=tags
6+
#
7+
# This file is based on these images:
8+
#
9+
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
10+
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20240904-slim - for the release image
11+
# - https://pkgs.org/ - resource for finding needed packages
12+
# - Ex: hexpm/elixir:1.17.3-erlang-27.0.1-debian-bullseye-20240904-slim
13+
#
114
ARG ELIXIR_VERSION=1.17.3
2-
ARG OTP_VERSION=27.1
3-
ARG ALPINE_VERSION=3.19.3
15+
ARG OTP_VERSION=27.0.1
16+
ARG DEBIAN_VERSION=bullseye-20240904-slim
417

5-
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-alpine-${ALPINE_VERSION}"
6-
ARG RUNNER_IMAGE="alpine:${ALPINE_VERSION}"
18+
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
19+
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
720

821
FROM ${BUILDER_IMAGE} as builder
9-
ENV MIX_ENV="prod"
1022

23+
# install build dependencies
24+
RUN apt-get update -y && apt-get install -y build-essential git \
25+
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
26+
27+
# prepare build dir
1128
WORKDIR /app
1229

13-
# install build tools
30+
# install hex + rebar
1431
RUN mix local.hex --force && \
1532
mix local.rebar --force
1633

34+
# set build ENV
35+
ENV MIX_ENV="prod"
36+
1737
# install mix dependencies
1838
COPY mix.exs mix.lock ./
1939
RUN mix deps.get --only $MIX_ENV
2040
RUN mkdir config
2141

22-
# Copy files
42+
# copy compile-time config files before we compile dependencies
43+
# to ensure any relevant config change will trigger the dependencies
44+
# to be re-compiled.
2345
COPY config/config.exs config/${MIX_ENV}.exs config/
46+
RUN mix deps.compile
47+
2448
COPY priv priv
49+
2550
COPY lib lib
2651

27-
# Compile then create binary
52+
# Compile the release
2853
RUN mix compile
29-
RUN mix release
3054

55+
# Changes to config/runtime.exs don't require recompiling the code
3156
COPY config/runtime.exs config/
3257

58+
COPY rel rel
59+
RUN mix release
60+
61+
# start a new build stage so that the final image will only contain
62+
# the compiled release and other runtime necessities
3363
FROM ${RUNNER_IMAGE}
3464

65+
RUN apt-get update -y && \
66+
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
67+
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
68+
3569
# Set the locale
70+
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
71+
3672
ENV LANG en_US.UTF-8
3773
ENV LANGUAGE en_US:en
3874
ENV LC_ALL en_US.UTF-8
@@ -48,4 +84,9 @@ COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/timecopsync_p
4884

4985
USER nobody
5086

51-
CMD ["/app/bin/server"]
87+
# If using an environment that doesn't automatically reap zombie processes, it is
88+
# advised to add an init process such as tini via `apt-get install`
89+
# above and adding an entrypoint. See https://github.com/krallin/tini for details
90+
# ENTRYPOINT ["/tini", "--"]
91+
92+
CMD ["/app/bin/server"]
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
defmodule TimecopsyncProjectsApi.Release do
2+
@moduledoc """
3+
Used for executing DB release tasks when run in production without Mix
4+
installed.
5+
"""
6+
@app :timecopsync_projects_api
7+
8+
def migrate do
9+
load_app()
10+
11+
for repo <- repos() do
12+
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
13+
end
14+
end
15+
16+
def rollback(repo, version) do
17+
load_app()
18+
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
19+
end
20+
21+
defp repos do
22+
Application.fetch_env!(@app, :ecto_repos)
23+
end
24+
25+
defp load_app do
26+
Application.load(@app)
27+
end
28+
end

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule TimecopsyncProjectsApi.MixProject do
44
def project do
55
[
66
app: :timecopsync_projects_api,
7-
version: "1.0.0",
7+
version: "1.0.1",
88
elixir: "~> 1.14",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
start_permanent: Mix.env() == :prod,

rel/overlays/bin/migrate

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
cd -P -- "$(dirname -- "$0")"
5+
exec ./timecopsync_projects_api eval TimecopsyncProjectsApi.Release.migrate

rel/overlays/bin/migrate.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
call "%~dp0\timecopsync_projects_api" eval TimecopsyncProjectsApi.Release.migrate

rel/overlays/bin/server

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
cd -P -- "$(dirname -- "$0")"
5+
PHX_SERVER=true exec ./timecopsync_projects_api start

rel/overlays/bin/server.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set PHX_SERVER=true
2+
call "%~dp0\timecopsync_projects_api" start

0 commit comments

Comments
 (0)