-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Connor Rigby <[email protected]>
- Loading branch information
1 parent
5e4e92e
commit 07e96ea
Showing
24 changed files
with
278 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ priv/static | |
test | ||
.env | ||
.cache | ||
backup | ||
erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ npm-debug.log | |
|
||
*.env | ||
deploy.sh | ||
backup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
erlang 24.0.3 | ||
elixir 1.12.2-otp-24 | ||
nodejs 16.3.0 | ||
erlang 26.0 | ||
elixir 1.14.5-otp-26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,91 @@ | ||
# prepare release image | ||
FROM alpine:3.14 AS app_base | ||
WORKDIR /app | ||
RUN apk add --no-cache libstdc++ openssl ncurses-libs bash | ||
|
||
FROM erlang:24.0.3-alpine as build | ||
ENV ELIXIR_VERSION="v1.12.2-otp-24" | ||
|
||
# # install elixir | ||
RUN wget https://repo.hex.pm/builds/elixir/$ELIXIR_VERSION.zip && \ | ||
mkdir -p /usr/local/elixir && \ | ||
unzip -q -d /usr/local/elixir $ELIXIR_VERSION.zip | ||
ENV PATH=/usr/local/elixir/bin:$PATH | ||
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of | ||
# Alpine to avoid DNS resolution issues in production. | ||
# | ||
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu | ||
# https://hub.docker.com/_/ubuntu?tab=tags | ||
# | ||
# | ||
# This file is based on these images: | ||
# | ||
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image | ||
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20221004-slim - for the release image | ||
# - https://pkgs.org/ - resource for finding needed packages | ||
# - Ex: hexpm/elixir:1.14.2-erlang-25.1.2-debian-bullseye-20221004-slim | ||
# | ||
ARG ELIXIR_VERSION=1.14.5 | ||
ARG OTP_VERSION=26.0 | ||
ARG DEBIAN_VERSION=bullseye-20230227-slim | ||
|
||
RUN apk add libstdc++ bash make alpine-sdk | ||
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" | ||
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" | ||
|
||
RUN mix do local.hex --force, local.rebar --force | ||
FROM ${BUILDER_IMAGE} as builder | ||
|
||
FROM build AS deps | ||
# install build dependencies | ||
RUN apt-get update -y && apt-get install -y build-essential git nodejs npm\ | ||
&& apt-get clean && rm -f /var/lib/apt/lists/*_* | ||
|
||
# prepare build dir | ||
WORKDIR /app | ||
|
||
ARG SECRET_KEY_BASE | ||
ARG DATABASE_URL | ||
ARG DISCORD_TOKEN | ||
ARG DISCORD_CLIENT_ID | ||
ARG DISCORD_CLIENT_SECRET | ||
ARG PORT=4000 | ||
ARG COMMIT | ||
ARG PARTPICKER_API_TOKEN | ||
ARG FREENODE_PASSWORD | ||
ARG TRACKER_GG_TOKEN | ||
|
||
ENV MIX_ENV=prod | ||
ENV SECRET_KEY_BASE=${SECRET_KEY_BASE} | ||
ENV DATABASE_URL=${DATABASE_URL} | ||
ENV DISCORD_TOKEN=${DISCORD_TOKEN} | ||
ENV DISCORD_CLIENT_ID=${DISCORD_CLIENT_ID} | ||
ENV DISCORD_CLIENT_SECRET=${DISCORD_CLIENT_SECRET} | ||
ENV PARTPICKER_API_TOKEN=${PARTPICKER_API_TOKEN} | ||
ENV TRACKER_GG_TOKEN=${TRACKER_GG_TOKEN} | ||
ENV PORT=${PORT} | ||
ENV COMMIT=${COMMIT} | ||
# 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 | ||
RUN mix deps.get --only $MIX_ENV | ||
RUN mkdir config | ||
|
||
FROM deps as compile | ||
# copy compile-time config files before we compile dependencies | ||
# to ensure any relevant config change will trigger the dependencies | ||
# to be re-compiled. | ||
COPY config/config.exs config/${MIX_ENV}.exs config/ | ||
RUN mix deps.compile | ||
|
||
# compile and build release | ||
COPY lib lib | ||
COPY config config | ||
COPY rel rel | ||
COPY priv priv | ||
|
||
COPY lib lib | ||
|
||
# Compile the release | ||
RUN mix compile | ||
|
||
FROM compile as release | ||
# Changes to config/runtime.exs don't require recompiling the code | ||
COPY config/runtime.exs config/ | ||
|
||
COPY rel rel | ||
RUN mix release | ||
|
||
# start a new build stage so that the final image will only contain | ||
# the compiled release and other runtime necessities | ||
FROM ${RUNNER_IMAGE} | ||
|
||
RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \ | ||
&& apt-get clean && rm -f /var/lib/apt/lists/*_* | ||
|
||
# Set the locale | ||
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen | ||
|
||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
|
||
WORKDIR "/app" | ||
RUN chown nobody /app | ||
|
||
# set runner ENV | ||
ENV MIX_ENV="prod" | ||
|
||
# Only copy the final release from the build stage | ||
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/miata_bot ./ | ||
|
||
RUN mix release --overwrite | ||
USER nobody | ||
|
||
FROM app_base as app | ||
COPY --from=release --chown=nobody:nobody /app/_build/prod/rel/miata_bot ./ | ||
RUN chown nobody:nobody /app | ||
CMD ["/app/bin/miata_bot", "start"] | ||
|
||
USER nobody:nobody | ||
ENV HOME=/app | ||
ENTRYPOINT ["bin/miata_bot", "start"] | ||
# Appended by flyctl | ||
ENV ECTO_IPV6 true | ||
ENV ERL_AFLAGS "-proto_dist inet6_tcp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use Mix.Config | ||
import Config | ||
|
||
# Configure your database | ||
config :miata_bot, MiataBot.Repo, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1 @@ | ||
import Config | ||
|
||
partpicker_api_token = | ||
System.get_env("PARTPICKER_API_TOKEN") || | ||
raise """ | ||
environment variable PARTPICKER_API_TOKEN is missing. | ||
This must be generated by the partpicker admins for production environment | ||
""" | ||
|
||
config :miata_bot, MiataBot.Partpicker, | ||
api_token: partpicker_api_token, | ||
base_url: "https://miatapartpicker.gay/api" | ||
|
||
database_url = | ||
System.get_env("DATABASE_URL") || | ||
raise """ | ||
environment variable DATABASE_URL is missing. | ||
For example: ecto://USER:PASS@HOST/DATABASE | ||
""" | ||
|
||
quarrel_database_url = | ||
URI.parse(database_url) | ||
|> Map.put(:path, "/miata_bot_quarrel") | ||
|> to_string | ||
|
||
config :miata_bot, MiataBot.Repo, | ||
url: database_url, | ||
pool_size: 10 | ||
|
||
config :quarrel, Quarrel.Repo, | ||
url: quarrel_database_url, | ||
pool_size: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Config | ||
|
||
config :tesla, adapter: Tesla.Adapter.Hackney | ||
|
||
if System.get_env("RELEASE_MODE") do | ||
partpicker_api_token = | ||
System.get_env("PARTPICKER_API_TOKEN") || | ||
raise """ | ||
environment variable PARTPICKER_API_TOKEN is missing. | ||
This must be generated by the partpicker admins for production environment | ||
""" | ||
|
||
config :miata_bot, MiataBot.Partpicker, | ||
api_token: partpicker_api_token, | ||
base_url: "https://partpicker.fly.dev/api" | ||
|
||
database_url = | ||
System.get_env("DATABASE_URL") || | ||
raise """ | ||
environment variable DATABASE_URL is missing. | ||
For example: ecto://USER:PASS@HOST/DATABASE | ||
""" | ||
|
||
config :miata_bot, MiataBot.Repo, | ||
url: database_url, | ||
pool_size: 10, | ||
socket_options: [:inet6] | ||
|
||
quarrel_database_url = | ||
URI.parse(database_url) | ||
|> Map.put(:path, "/miata_bot_quarrel") | ||
|> to_string | ||
|
||
config :quarrel, Quarrel.Repo, | ||
url: quarrel_database_url, | ||
pool_size: 10, | ||
socket_options: [:inet6] | ||
|
||
config :nostrum, | ||
token: System.get_env("DISCORD_TOKEN"), | ||
gateway_intents: :all, | ||
num_shards: :auto | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# fly.toml app configuration file generated for miata-bot on 2023-05-29T16:09:46-06:00 | ||
# | ||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file. | ||
# | ||
|
||
app = "miata-bot" | ||
primary_region = "den" | ||
|
||
[env] | ||
PORT = "8080" | ||
ECTO_IPV6=true | ||
ERL_AFLAGS="-proto_dist inet6_tcp" | ||
|
||
[http_service] | ||
internal_port = 8080 | ||
force_https = true | ||
auto_stop_machines = false | ||
auto_start_machines = true | ||
min_machines_running = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.