Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
railway-bot committed Feb 1, 2024
0 parents commit 55e8c55
Show file tree
Hide file tree
Showing 63 changed files with 3,742 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
47 changes: 47 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Elixir CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}

env:
MIX_ENV: test
TEST_ENV: github

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

strategy:
matrix:
otp: ['24.x', '25.x']
elixir: ['1.12.3', '1.13.4', '1.14.3']
exclude:
- otp: '25.x'
elixir: '1.12.3'

steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- run: mix do deps.get, deps.compile
- run: mix do ecto.create, ecto.migrate
- run: mix test
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Docker Release

on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

strategy:
matrix:
include:
- arch: linux/amd64
FORCE_RUST_BUILD: 0
#- arch: linux/arm64
# FORCE_RUST_BUILD: 1

steps:
- uses: actions/checkout@v3
- uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@v2
- uses: docker/metadata-action@v4
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: ${{ matrix.arch }}
build-args: FORCE_RUST_BUILD=${{ matrix.FORCE_RUST_BUILD }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
nex-*.tar

# Temporary files, for example, from tests.
/tmp/

# Local ignores
.DS_Store
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
##
# BUILD STAGE
# ===========
FROM elixir:1.14-otp-24-alpine AS build

# Install build deps
RUN apk update && \
apk add --no-cache bash build-base curl git libgcc python3

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV RUSTUP_HOME=/root/.rustup \
RUSTFLAGS="-C target-feature=-crt-static" \
CARGO_HOME=/root/.cargo \
PATH="/root/.cargo/bin:$PATH"

# Prepare build
WORKDIR /build
ENV HOME=/build
ENV MIX_ENV=prod
ARG FORCE_RUST_BUILD=0
ENV RUSTLER_PRECOMPILATION_EXAMPLE_BUILD=${FORCE_RUST_BUILD}

# Install Hex and Rebar
RUN mix local.hex --force && \
mix local.rebar --force

# Install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix do deps.get, deps.compile

# Compile app
COPY lib lib
COPY priv priv
RUN mix compile
RUN mix release

##
# APP STAGE
# =========
FROM alpine:3.16 AS app

LABEL org.opencontainers.image.title="Nex"
LABEL org.opencontainers.image.description="Nex is a performance nostr relay, written in Elixir"
LABEL org.opencontainers.image.source="https://github.com/lebrunel/nex"
LABEL org.opencontainers.image.source="https://hexdocs.pm/nex"
LABEL org.opencontainers.image.authors="lebrunel"
LABEL org.opencontainers.image.licenses="Apache-2.0"

# Runtime deps
RUN apk update && \
apk add --no-cache bash libgcc libstdc++ ncurses-libs openssl-dev

RUN mkdir /app
WORKDIR /app

COPY --from=build /build/_build/prod/rel/nex ./

CMD ["bin/nex", "start"]
30 changes: 30 additions & 0 deletions Dockerfile.railway
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ghcr.io/lebrunel/nex:latest

WORKDIR /app

ARG PORT
ARG DATABASE_URL
ARG PGHOST
ARG PGPORT
ARG PGDATABASE
ARG PGUSER
ARG PGPASSWORD

ENV PORT=$PORT
ENV DATABASE_URL=$DATABASE_URL
ENV DB_HOST=$PGHOST
ENV DB_PORT=$PGPORT
ENV DB_NAME=$PGDATABASE
ENV DB_USER=$PGUSER
ENV DB_PASSWORD=$PGPASSWORD

RUN bin/nex eval "Nex.Release.migrate()"

LABEL org.opencontainers.image.title="Nex"
LABEL org.opencontainers.image.description="Nex is a performance nostr relay, written in Elixir"
LABEL org.opencontainers.image.source="https://github.com/lebrunel/nex"
LABEL org.opencontainers.image.source="https://hexdocs.pm/nex"
LABEL org.opencontainers.image.authors="lebrunel"
LABEL org.opencontainers.image.licenses="Apache-2.0"

CMD ["bin/nex", "start"]
Loading

0 comments on commit 55e8c55

Please sign in to comment.