Skip to content

Commit

Permalink
Rename Enlil -> Share (#1)
Browse files Browse the repository at this point in the history
* Rewrite module names

* Rewrite enlil packages to share packages

* Rewrite docker enlil -> share

* Rewrite enlil -> share in source

* Rewrite makefile enlil -> share

* Rewrite ci enlil -> share

* Speed up docker builds
  • Loading branch information
ChrisPenner authored May 7, 2024
1 parent 2848c14 commit 63928c6
Show file tree
Hide file tree
Showing 187 changed files with 1,594 additions and 1,596 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.github/ @unisoncomputing/share
29 changes: 14 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ jobs:
submodules: false
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
uses: tj-actions/changed-files@0874344d6ebbaa00a27da73276ae7162fadcaf69 # v44.3.0
with:
# globs copied from default settings for run-ormolu
files: |
**/*.hs
**/*.hs-boot
separator: "\n"
- uses: haskell-actions/run-ormolu@v15
- uses: haskell-actions/run-ormolu@15b0083a0ef416915994fb511652b187f6026a40 # v15.0.0
with:
version: ${{ env.ormolu_version }}
mode: inplace
pattern: ${{ steps.changed-files.outputs.all_changed_files }}
- name: apply formatting changes
uses: stefanzweifel/git-auto-commit-action@v5
uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5.0.1
# Only try to commit formatting changes if we're running within the repo containing the PR,
# and not on a protected branch.
# The job doesn't have permission to push back to contributor forks on contributor PRs.
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
${{ (env.is_published_build && '--ghc-options -O2') || '--fast' }}
- name: Save exes for docker build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: share-api-exe
path: ${{env.share_local_bin}}
Expand All @@ -96,7 +96,6 @@ jobs:

# A separate job for docker build because it requires elevated github token permissions.
docker-build:
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging') }}
env:
container_registry: ghcr.io
docker_image_name: ${{ github.repository }}
Expand All @@ -119,15 +118,15 @@ jobs:
submodules: false

# Downloads the artifact that contains the share-api-exe from the previous job.
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: share-api-exe
path: ./docker/tmp/

# Configure Docker's builder,
# This seems necessary to support docker cache layers.
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0


# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
Expand Down Expand Up @@ -156,7 +155,7 @@ jobs:
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v5
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
context: ./docker/
push: ${{ env.is_published_build }}
Expand All @@ -166,20 +165,20 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
ENLIL_COMMIT=${{ github.sha }}
SHARE_COMMIT=${{ github.sha }}
# Save image locally for use in tests even if we don't push it.
outputs: type=docker,dest=/tmp/share-docker-image.tar # export docker image

- name: Save docker image for transcript tests
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: share-docker-image
path: /tmp/share-docker-image.tar

# NOTE: disabled until repo goes public
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v1
# uses: actions/attest-build-provenance@v1.1.0
# with:
# subject-name: ${{ env.container_registry }}/${{ env.docker_image_name}}
# subject-digest: ${{ steps.push.outputs.digest }}
Expand Down Expand Up @@ -207,17 +206,17 @@ jobs:
# Configure Docker's builder,
# This seems necessary to support docker cache layers.
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0

- name: Download artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: share-docker-image
path: /tmp

# Load this before using docker and it'll cache images we use in the docker-compose
- name: Cache Docker images.
uses: ScribeMD/docker-cache@0.5.0
uses: ScribeMD/docker-cache@fb28c93772363301b8d0a6072ce850224b73f74e # v0.5.0
with:
key: docker-${{ runner.os }} }}

Expand All @@ -243,7 +242,7 @@ jobs:
# Clean up old postgres data if it exists.
docker volume rm docker_postgresVolume 2>/dev/null || true
# Start enlil and it's dependencies in the background
# Start share and it's dependencies in the background
docker compose -f docker/docker-compose.yml up --wait
# Run the transcript tests
Expand Down
23 changes: 11 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
UNAME := $(shell uname)
STACK_FLAGS := "--fast"
dist_dir := $(shell stack path | awk '/^dist-dir/{print $$2}')
exe_name := enlil-exe
inst_exe_name := enlil
exe_name := share-api
exe := $(dist_dir)/build/$(exe_name)/$(exe_name)
target_dir := docker/tmp
installed_enlil := $(target_dir)/$(inst_exe_name)
installed_share := $(target_dir)/$(exe_name)
unison := $(shell command -v unison)
docker_registry=324181518966.dkr.ecr.us-west-2.amazonaws.com
enlil_commit := $(shell git diff-index --quiet HEAD -- && git rev-parse --short=10 HEAD || echo 'wip')
share_commit := $(shell git diff-index --quiet HEAD -- && git rev-parse --short=10 HEAD || echo 'wip')

OPEN_BROWSER ?= "true"

Expand All @@ -29,30 +28,30 @@ $(target_dir):
$(exe): $(shell find . unison -type f -name '*.hs') package.yaml stack.yaml
@echo $(exe)
@echo $@
stack build $(STACK_FLAGS) enlil:enlil-exe
stack build $(STACK_FLAGS) share-api:share-api

$(installed_enlil): $(exe) $(target_dir)
cp $(exe) $(installed_enlil)
$(installed_share): $(exe) $(target_dir)
cp $(exe) $(installed_share)

auth_example:
stack build --fast test-auth-app

docker_server_build: $(installed_enlil)
docker build $(docker_platform_flag) -f docker/Dockerfile --build-arg ENLIL_COMMIT=$(enlil_commit) -t share docker
docker_server_build: $(installed_share)
docker build $(docker_platform_flag) -f docker/Dockerfile --build-arg share_commit=$(share_commit) -t share docker

docker_server_release: $(installed_enlil)
docker_server_release: $(installed_share)
docker build $(docker_platform_flag) -f docker/Dockerfile -t $(docker_registry)/share:$(DRONE_BUILD_NUMBER) docker

docker_push: $(docker_server_release)
docker push $(docker_registry)/share:$(DRONE_BUILD_NUMBER)

docker_staging_release: $(installed_enlil)
docker_staging_release: $(installed_share)
docker build $(docker_platform_flag) -f docker/Dockerfile -t $(docker_registry)/share-staging:$(DRONE_BUILD_NUMBER) docker

docker_staging_push: $(docker_server_release)
docker push $(docker_registry)/share-staging:$(DRONE_BUILD_NUMBER)

serve: $(installed_enlil)
serve: $(installed_share)
trap 'docker-compose -f docker/docker-compose.yml down' EXIT INT TERM
docker-compose -f docker/docker-compose.yml up postgres redis &
while ! ( pg_isready --host localhost -U postgres -p 5432 && redis-cli -p 6379 ping) do \
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Unison Share

Note: Originally this project was named `Enlil`, there are many references to `Enlil` in the codebase and documentation, you may mentally substitute `Share` into those spots instead.

* [Setup](#setup)
* [MacOS](#macos)
* [Nix](#nix)
Expand Down
58 changes: 29 additions & 29 deletions app/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import Data.Set qualified as Set
import Data.Text qualified as Text
import Data.Text.Encoding qualified as Text
import Database.Redis qualified as Redis
import Enlil.Env
import Enlil.JWT qualified as JWT
import Enlil.Prelude
import Enlil.Utils.Deployment qualified as Deployment
import Enlil.Utils.Logging qualified as Logging
import Enlil.Utils.Servant.Cookies qualified as Cookies
import Enlil.Web.Authentication (cookieSessionTTL)
import Share.Env
import Share.JWT qualified as JWT
import Share.Prelude
import Share.Utils.Deployment qualified as Deployment
import Share.Utils.Logging qualified as Logging
import Share.Utils.Servant.Cookies qualified as Cookies
import Share.Web.Authentication (cookieSessionTTL)
import Hasql.Pool qualified as Pool
import Network.URI (parseURI)
import Servant.API qualified as Servant
Expand All @@ -35,42 +35,42 @@ import Unison.Runtime.Interface as RT

withEnv :: (Env () -> IO a) -> IO a
withEnv action = do
apiOrigin <- fromEnv "ENLIL_API_ORIGIN" (pure . maybeToEither "Invalid ENLIL_API_ORIGIN" . parseURI)
serverPort <- fromEnv "ENLIL_SERVER_PORT" readPort
apiOrigin <- fromEnv "SHARE_API_ORIGIN" (pure . maybeToEither "Invalid SHARE_API_ORIGIN" . parseURI)
serverPort <- fromEnv "SHARE_SERVER_PORT" readPort
shouldCheckForMigration <-
lookupEnv "ENLIL_MIGRATE_ON_STARTUP" <&> \case
lookupEnv "SHARE_MIGRATE_ON_STARTUP" <&> \case
Nothing -> False
Just val -> case map Char.toLower val of
'f' : _ -> False
'0' : _ -> False
[] -> False
_ -> True
postgresConfig <- fromEnv "ENLIL_POSTGRES" (pure . Right . Text.pack)
postgresConnMax <- fromEnv "ENLIL_POSTGRES_CONN_MAX" (pure . maybeToEither "Invalid ENLIL_POSTGRES_CONN_MAX" . readMaybe)
githubClientID <- fromEnv "ENLIL_GITHUB_CLIENTID" (pure . Right . Text.pack)
githubClientSecret <- fromEnv "ENLIL_GITHUB_CLIENT_SECRET" (pure . Right . Text.pack)
hs256Key <- fromEnv "ENLIL_HMAC_KEY" (pure . Right . BS.pack)
zendeskAPIUser <- fromEnv "ENLIL_ZENDESK_API_USER" (pure . Right . BS.pack)
zendeskAPIToken <- fromEnv "ENLIL_ZENDESK_API_TOKEN" (pure . Right . BS.pack)
postgresConfig <- fromEnv "SHARE_POSTGRES" (pure . Right . Text.pack)
postgresConnMax <- fromEnv "SHARE_POSTGRES_CONN_MAX" (pure . maybeToEither "Invalid SHARE_POSTGRES_CONN_MAX" . readMaybe)
githubClientID <- fromEnv "SHARE_GITHUB_CLIENTID" (pure . Right . Text.pack)
githubClientSecret <- fromEnv "SHARE_GITHUB_CLIENT_SECRET" (pure . Right . Text.pack)
hs256Key <- fromEnv "SHARE_HMAC_KEY" (pure . Right . BS.pack)
zendeskAPIUser <- fromEnv "SHARE_ZENDESK_API_USER" (pure . Right . BS.pack)
zendeskAPIToken <- fromEnv "SHARE_ZENDESK_API_TOKEN" (pure . Right . BS.pack)
let zendeskAuth = Servant.BasicAuthData zendeskAPIUser zendeskAPIToken
commitHash <- fromEnv "ENLIL_COMMIT" (pure . Right . Text.pack)
commitHash <- fromEnv "SHARE_COMMIT" (pure . Right . Text.pack)
minLogSeverity <-
lookupEnv "ENLIL_LOG_LEVEL" >>= \case
lookupEnv "SHARE_LOG_LEVEL" >>= \case
Nothing -> pure Logging.Info
Just (map toUpper -> "DEBUG") -> pure Logging.Debug
Just (map toUpper -> "INFO") -> pure Logging.Info
Just (map toUpper -> "ERROR") -> pure Logging.Error
Just (map toUpper -> "USERERROR") -> pure Logging.UserFault
Just x -> putStrLn ("Unknown logging level: " <> x) >> exitWith (ExitFailure 1)
shareUiOrigin <- fromEnv "ENLIL_SHARE_UI_ORIGIN" (pure . maybeToEither "Invalid ENLIL_SHARE_UI_ORIGIN" . parseURI)
websiteOrigin <- fromEnv "ENLIL_HOMEPAGE_ORIGIN" (pure . maybeToEither "Invalid ENLIL_HOMEPAGE_ORIGIN" . parseURI)
cloudUiOrigin <- fromEnv "ENLIL_CLOUD_UI_ORIGIN" (pure . maybeToEither "Invalid ENLIL_CLOUD_UI_ORIGIN" . parseURI)
maxParallelismPerDownloadRequest <- fromEnv "ENLIL_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST" (pure . maybeToEither "Invalid ENLIL_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST" . readMaybe)
maxParallelismPerUploadRequest <- fromEnv "ENLIL_MAX_PARALLELISM_PER_UPLOAD_REQUEST" (pure . maybeToEither "Invalid ENLIL_MAX_PARALLELISM_PER_UPLOAD_REQUEST" . readMaybe)
cloudWebsiteOrigin <- fromEnv "ENLIL_CLOUD_HOMEPAGE_ORIGIN" (pure . maybeToEither "Invalid ENLIL_CLOUD_HOMEPAGE_ORIGIN" . parseURI)
shareUiOrigin <- fromEnv "SHARE_SHARE_UI_ORIGIN" (pure . maybeToEither "Invalid SHARE_SHARE_UI_ORIGIN" . parseURI)
websiteOrigin <- fromEnv "SHARE_HOMEPAGE_ORIGIN" (pure . maybeToEither "Invalid SHARE_HOMEPAGE_ORIGIN" . parseURI)
cloudUiOrigin <- fromEnv "SHARE_CLOUD_UI_ORIGIN" (pure . maybeToEither "Invalid SHARE_CLOUD_UI_ORIGIN" . parseURI)
maxParallelismPerDownloadRequest <- fromEnv "SHARE_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST" (pure . maybeToEither "Invalid SHARE_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST" . readMaybe)
maxParallelismPerUploadRequest <- fromEnv "SHARE_MAX_PARALLELISM_PER_UPLOAD_REQUEST" (pure . maybeToEither "Invalid SHARE_MAX_PARALLELISM_PER_UPLOAD_REQUEST" . readMaybe)
cloudWebsiteOrigin <- fromEnv "SHARE_CLOUD_HOMEPAGE_ORIGIN" (pure . maybeToEither "Invalid SHARE_CLOUD_HOMEPAGE_ORIGIN" . parseURI)

sentryService <-
lookupEnv "ENLIL_SENTRY_DSN" >>= \case
lookupEnv "SHARE_SENTRY_DSN" >>= \case
Nothing -> do
putStrLn "No Sentry configuration detected."
Sentry.disabledRaven
Expand All @@ -80,7 +80,7 @@ withEnv action = do
Sentry.initRaven dsn sentryTags Sentry.sendRecord Sentry.stderrFallback

redisConfig <-
(fromEnv "ENLIL_REDIS" (pure . Redis.parseConnectInfo)) <&> \r ->
(fromEnv "SHARE_REDIS" (pure . Redis.parseConnectInfo)) <&> \r ->
let tlsParams
| Deployment.onLocal = Nothing
| otherwise = Nothing
Expand All @@ -93,15 +93,15 @@ withEnv action = do
pgConnectionPool <-
Pool.acquire postgresConnMax Nothing (Text.encodeUtf8 postgresConfig)
timeCache <- FL.newTimeCache FL.simpleTimeFormat -- E.g. 05/Sep/2023:13:23:56 -0700
sandboxedRuntime <- RT.startRuntime True RT.Persistent "enlil"
sandboxedRuntime <- RT.startRuntime True RT.Persistent "share"
let requestCtx = ()
-- We use a zero-width-space to separate log-lines on ingestion, this allows us to use newlines for
-- formatting, but without affecting log-grouping.
let zeroWidthSpace = "\x200B"
FL.withFastLogger (FL.LogStderr FL.defaultBufSize) $ \logger -> do
action $ Env {logger = (logger . (\msg -> zeroWidthSpace <> msg <> "\n")), ..}
where
readPort p = pure $ maybeToRight "ENLIL_PORT was not a number" (readMaybe p)
readPort p = pure $ maybeToRight "SHARE_PORT was not a number" (readMaybe p)

fromEnv :: String -> (String -> IO (Either String a)) -> IO a
fromEnv var from = do
Expand Down
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Main where

import Enlil
import Share
import Env (withEnv)

main :: IO ()
Expand Down
16 changes: 8 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
FROM debian:bookworm
RUN apt-get update && apt-get install -y ssl-cert libpq5 ca-certificates curl locales
RUN openssl genrsa -out /etc/ssl/private/enlil.key &&\
RUN openssl genrsa -out /etc/ssl/private/share.key &&\
echo "C.UTF-8 UTF-8" > /etc/locale.gen &&\
dpkg-reconfigure --frontend=noninteractive locales &&\
update-locale LANG=C.UTF-8
ENV LANG=C.UTF-8

COPY enlil-entrypoint.sh /usr/local/bin/enlil-entrypoint
RUN chmod 555 /usr/local/bin/enlil-entrypoint
COPY share-entrypoint.sh /usr/local/bin/share-entrypoint
RUN chmod 555 /usr/local/bin/share-entrypoint

COPY tmp/enlil-exe /usr/local/bin/enlil
RUN chmod 555 /usr/local/bin/enlil
COPY tmp/share-api /usr/local/bin/share
RUN chmod 555 /usr/local/bin/share

ENTRYPOINT /usr/local/bin/enlil-entrypoint
ENTRYPOINT /usr/local/bin/share-entrypoint

ARG ENLIL_COMMIT
ENV ENLIL_COMMIT=$ENLIL_COMMIT
ARG SHARE_COMMIT
ENV SHARE_COMMIT=$SHARE_COMMIT
50 changes: 25 additions & 25 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@ services:

environment:
# Placeholder values for development
- ENLIL_API_ORIGIN=http://enlil
- ENLIL_SERVER_PORT=5424
- ENLIL_ADMIN_PORT=5425
- ENLIL_CLIENT_HOSTNAME=0.0.0.0
- ENLIL_CLIENT_PORT=5426
- ENLIL_REDIS=redis://redis:6379
- ENLIL_POSTGRES=postgresql://postgres:sekrit@postgres:5432
- ENLIL_HMAC_KEY=test-key-test-key-test-key-test-key-
- ENLIL_DEPLOYMENT=local
- ENLIL_IP=enlil
- ENLIL_AWS_CREDENTIAL_URL=invalid
- SHARE_API_ORIGIN=http://share-api
- SHARE_SERVER_PORT=5424
- SHARE_ADMIN_PORT=5425
- SHARE_CLIENT_HOSTNAME=0.0.0.0
- SHARE_CLIENT_PORT=5426
- SHARE_REDIS=redis://redis:6379
- SHARE_POSTGRES=postgresql://postgres:sekrit@postgres:5432
- SHARE_HMAC_KEY=test-key-test-key-test-key-test-key-
- SHARE_DEPLOYMENT=local
- SHARE_IP=share-api
- SHARE_AWS_CREDENTIAL_URL=invalid
- AWS_REGION=invalid
- ENLIL_POSTGRES_CONN_TTL=30
- ENLIL_POSTGRES_CONN_MAX=10
- ENLIL_SHARE_UI_ORIGIN=http://localhost:1234
- ENLIL_CLOUD_UI_ORIGIN=http://localhost:5678
- ENLIL_HOMEPAGE_ORIGIN=http://localhost:1111
- ENLIL_CLOUD_HOMEPAGE_ORIGIN=http://localhost:2222
- ENLIL_LOG_LEVEL=DEBUG
- ENLIL_COMMIT=dev
- ENLIL_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST=1
- ENLIL_MAX_PARALLELISM_PER_UPLOAD_REQUEST=5
- ENLIL_ZENDESK_API_USER[email protected]
- ENLIL_ZENDESK_API_TOKEN=bad-password
- ENLIL_GITHUB_CLIENTID=invalid
- ENLIL_GITHUB_CLIENT_SECRET=invalid
- SHARE_POSTGRES_CONN_TTL=30
- SHARE_POSTGRES_CONN_MAX=10
- SHARE_SHARE_UI_ORIGIN=http://localhost:1234
- SHARE_CLOUD_UI_ORIGIN=http://localhost:5678
- SHARE_HOMEPAGE_ORIGIN=http://localhost:1111
- SHARE_CLOUD_HOMEPAGE_ORIGIN=http://localhost:2222
- SHARE_LOG_LEVEL=DEBUG
- SHARE_COMMIT=dev
- SHARE_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST=1
- SHARE_MAX_PARALLELISM_PER_UPLOAD_REQUEST=5
- SHARE_ZENDESK_API_USER[email protected]
- SHARE_ZENDESK_API_TOKEN=bad-password
- SHARE_GITHUB_CLIENTID=invalid
- SHARE_GITHUB_CLIENT_SECRET=invalid
- AWS_ACCESS_KEY_ID=invalid
- AWS_SECRET_ACCESS_KEY=invalid

Expand Down
Loading

0 comments on commit 63928c6

Please sign in to comment.