Skip to content

Commit

Permalink
Merge pull request #12 from jehrhardt/ee-ce-versions
Browse files Browse the repository at this point in the history
Add support for CE and EE versions
  • Loading branch information
jehrhardt authored Sep 20, 2024
2 parents 86d3232 + 369b435 commit ff9d8b5
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 15 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# Common development/test artifacts
/cover/
/doc/
/docs/
/test/
/tmp/
.elixir_ls
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ jobs:

build-image:

name: Build container image
name: Build ${{ matrix.env }} container image
runs-on: ubuntu-latest

strategy:
matrix:
env: [prod, ce]

steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
Expand All @@ -67,11 +71,13 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.env }}
- name: Build
uses: docker/build-push-action@v6
with:
context: .
push: false
build-args: |
MIX_ENV=${{ matrix.env }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
43 changes: 43 additions & 0 deletions .github/workflows/publish-containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish Container Images

on:
push:
branches: [main]

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

jobs:
push-image:

name: Build and publish ${{ matrix.env }} container image
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

strategy:
matrix:
env: [prod, ce]

steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.env }}
- name: Build
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
MIX_ENV=${{ matrix.env }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ WORKDIR /app
RUN mix local.hex --force && \
mix local.rebar --force

# download Supabase SSL ca-certificate
RUN curl -L https://supabase-downloads.s3-ap-southeast-1.amazonaws.com/prod/ssl/prod-ca-2021.crt -o prod-ca-2021.crt

# set build ENV
ENV MIX_ENV="prod"
ARG MIX_ENV="ce"
ENV ERL_FLAGS="+JPperf true"

# Download Supabase TLS ca-certificate
RUN mkdir certs \
&& if [ "${MIX_ENV}" = "prod" ]; then curl -L https://supabase-downloads.s3-ap-southeast-1.amazonaws.com/prod/ssl/prod-ca-2021.crt -o certs/prod-ca-2021.crt; fi

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
Expand All @@ -32,6 +33,7 @@ RUN mix deps.compile
COPY priv priv

COPY lib lib
COPY ee ./ee

COPY assets assets

Expand All @@ -51,6 +53,10 @@ RUN mix release
# the compiled release and other runtime necessities
FROM ubuntu:noble-20240827.1

# set runner ENV
ARG MIX_ENV="ce"
ENV MIX_ENV=${MIX_ENV}

RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses6 locales ca-certificates \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
Expand All @@ -65,11 +71,8 @@ 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/prod-ca-2021.crt ./
COPY --from=builder --chown=nobody:root /app/certs ./
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/cozycoder ./

USER nobody
Expand Down
20 changes: 20 additions & 0 deletions config/ce.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Config

# Note we also include the path to a cache manifest
# containing the digested version of static files. This
# manifest is generated by the `mix assets.deploy` task,
# which you should run after static files are built and
# before starting your production server.
config :cozycoder, CozyCoderWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"

# Configures Swoosh API Client
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: CozyCoder.Finch

# Disable Swoosh Local Memory Storage
config :swoosh, local: false

# Do not print debug messages in production
config :logger, level: :info

# Runtime production configuration, including reading
# of environment variables, is done on config/runtime.exs.
3 changes: 3 additions & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Config

# Use Supabase TLS certificate for database connections.
config :cozycoder, CozyCoder.Repo, ssl: [cacertfile: "/app/prod-ca-2021.crt"]

# Note we also include the path to a cache manifest
# containing the digested version of static files. This
# manifest is generated by the `mix assets.deploy` task,
Expand Down
3 changes: 1 addition & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ if config_env() == :prod do
maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []

config :cozycoder, CozyCoder.Repo,
# Use Supabase TLS certificate
ssl: [cacertfile: "/app/prod-ca-2021.crt"],
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
socket_options: maybe_ipv6
Expand Down
3 changes: 3 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ kill_signal = 'SIGTERM'

[build]

[build.args]
MIX_ENV = "prod"

[deploy]
release_command = '/app/bin/migrate'

Expand Down
7 changes: 4 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule CozyCoder.MixProject do
version: "0.1.0",
elixir: "~> 1.17",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
start_permanent: Mix.env() in [:prod, :ce],
aliases: aliases(),
deps: deps()
]
Expand All @@ -24,8 +24,9 @@ defmodule CozyCoder.MixProject do
end

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
defp elixirc_paths(:test), do: ["lib", "test/support", "ee/lib"]
defp elixirc_paths(:ce), do: ["lib"]
defp elixirc_paths(_), do: ["lib", "ee/lib"]

# Specifies your project dependencies.
#
Expand Down

0 comments on commit ff9d8b5

Please sign in to comment.