Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
621 additions
and
82 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
_build/ | ||
.git/ | ||
webapp/node_modules/ | ||
priv/static/webapp | ||
deps/ | ||
test/ | ||
|
||
.* | ||
docker-compose.yml | ||
Makefile | ||
README.md | ||
Dockerfile |
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 |
---|---|---|
|
@@ -25,4 +25,5 @@ test.json | |
priv/static/webapp | ||
/webapp/node_modules | ||
/webapp/tmp | ||
/webapp/dist | ||
.elixir_ls |
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,77 @@ | ||
# | ||
# Step 1 - Build the OTP binary | ||
# | ||
FROM elixir:1.7.4-alpine AS builder | ||
|
||
ARG APP_NAME | ||
ARG APP_VERSION | ||
ARG MIX_ENV=prod | ||
|
||
ENV APP_NAME=${APP_NAME} \ | ||
APP_VERSION=${APP_VERSION} \ | ||
MIX_ENV=${MIX_ENV} | ||
|
||
WORKDIR /build | ||
|
||
# This step installs all the build tools we'll need | ||
RUN apk update && \ | ||
apk upgrade --no-cache && \ | ||
apk add --no-cache nodejs npm git build-base python yaml-dev | ||
|
||
RUN mix local.rebar --force && \ | ||
mix local.hex --force | ||
|
||
# This copies our app source code into the build container | ||
COPY mix.* ./ | ||
RUN mix deps.get --only ${MIX_ENV} | ||
RUN mix deps.compile | ||
|
||
COPY . . | ||
RUN mix compile | ||
RUN mix phx.digest | ||
|
||
RUN mkdir -p /opt/build && \ | ||
mix release --verbose && \ | ||
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VERSION}/${APP_NAME}.tar.gz /opt/build | ||
|
||
RUN cd /opt/build && \ | ||
tar -xzf ${APP_NAME}.tar.gz && \ | ||
rm ${APP_NAME}.tar.gz | ||
|
||
COPY webapp /opt/build/webapp | ||
|
||
RUN cd /opt/build && \ | ||
npm ci --prefix webapp --no-audit --no-color | ||
|
||
# | ||
# Step 2 - Build a lean runtime container | ||
# | ||
FROM alpine:3.8 | ||
|
||
ARG APP_NAME | ||
ARG APP_VERSION | ||
ENV APP_NAME=${APP_NAME} \ | ||
APP_VERSION=${APP_VERSION} | ||
|
||
# Update kernel and install runtime dependencies | ||
RUN apk --no-cache update && \ | ||
apk --no-cache upgrade && \ | ||
apk --no-cache add bash openssl yaml-dev nodejs npm | ||
|
||
WORKDIR /opt/accent | ||
|
||
# Copy the OTP binary from the build step | ||
COPY --from=builder /opt/build . | ||
|
||
# Copy the entrypoint script | ||
COPY priv/scripts/docker-entrypoint.sh /usr/local/bin | ||
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh | ||
|
||
# Create a non-root user | ||
RUN adduser -D accent && \ | ||
chown -R accent: /opt/accent | ||
|
||
USER accent | ||
|
||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
CMD ["foreground"] |
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,122 @@ | ||
# Configuration | ||
# ------------- | ||
|
||
APP_NAME ?= `grep 'app:' mix.exs | sed -e 's/\[//g' -e 's/ //g' -e 's/app://' -e 's/[:,]//g'` | ||
APP_VERSION ?= `grep 'version:' mix.exs | cut -d '"' -f2` | ||
DOCKER_IMAGE_TAG ?= latest | ||
GIT_REVISION ?= `git rev-parse HEAD` | ||
|
||
# Introspection targets | ||
# --------------------- | ||
|
||
.PHONY: help | ||
help: header targets | ||
|
||
.PHONY: header | ||
header: | ||
@echo "\033[34mEnvironment\033[0m" | ||
@echo "\033[34m---------------------------------------------------------------\033[0m" | ||
@printf "\033[33m%-23s\033[0m" "APP_NAME" | ||
@printf "\033[35m%s\033[0m" $(APP_NAME) | ||
@echo "" | ||
@printf "\033[33m%-23s\033[0m" "APP_VERSION" | ||
@printf "\033[35m%s\033[0m" $(APP_VERSION) | ||
@echo "" | ||
@printf "\033[33m%-23s\033[0m" "GIT_REVISION" | ||
@printf "\033[35m%s\033[0m" $(GIT_REVISION) | ||
@echo "" | ||
@printf "\033[33m%-23s\033[0m" "DOCKER_IMAGE_TAG" | ||
@printf "\033[35m%s\033[0m" $(DOCKER_IMAGE_TAG) | ||
@echo "\n" | ||
|
||
.PHONY: targets | ||
targets: | ||
@echo "\033[34mTargets\033[0m" | ||
@echo "\033[34m---------------------------------------------------------------\033[0m" | ||
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}' | ||
|
||
# Build targets | ||
# ------------- | ||
|
||
.PHONY: dependencies | ||
dependencies: dependencies-mix dependencies-npm ## Install dependencies required by the application | ||
|
||
.PHONY: dependencies-mix | ||
dependencies-mix: | ||
mix deps.get --force | ||
|
||
.PHONY: dependencies-npm | ||
dependencies-npm: | ||
npm install --prefix webapp | ||
|
||
.PHONY: build | ||
build: ## Build the Docker image for the OTP release | ||
docker build --build-arg APP_NAME=$(APP_NAME) --build-arg APP_VERSION=$(APP_VERSION) --rm --tag $(APP_NAME):$(DOCKER_IMAGE_TAG) . | ||
|
||
# CI targets | ||
# ---------- | ||
|
||
.PHONY: lint | ||
lint: lint-compile lint-format lint-credo lint-eslint lint-stylelint lint-prettier ## Run lint tools on the code | ||
|
||
.PHONY: lint-compile | ||
lint-compile: | ||
mix compile --warnings-as-errors --force | ||
|
||
.PHONY: lint-format | ||
lint-format: | ||
mix format --dry-run --check-formatted | ||
|
||
.PHONY: lint-credo | ||
lint-credo: | ||
mix credo --strict | ||
|
||
.PHONY: lint-eslint | ||
lint-eslint: | ||
./assets/node_modules/.bin/eslint --ignore-path webapp/.eslintignore --config webapp/.eslintrc webapp | ||
|
||
.PHONY: lint-stylelint | ||
lint-stylelint: | ||
./assets/node_modules/.bin/stylelint --syntax scss --config webapp/.stylelintrc webapp/css | ||
|
||
.PHONY: lint-prettier | ||
lint-prettier: | ||
./assets/node_modules/.bin/prettier --single-quote --list-different --no-bracket-spacing --print-width 130 './webapp/app/**/*.{js,gql}' | ||
|
||
.PHONY: test | ||
test: ## Run the test suite | ||
mix test | ||
|
||
.PHONY: test-coverage | ||
test-coverage: ## Generate the code coverage report | ||
mix coveralls | ||
|
||
.PHONY: format | ||
format: format-elixir format-prettier ## Run formatting tools on the code | ||
|
||
.PHONY: format-elixir | ||
format-elixir: | ||
mix format | ||
|
||
.PHONY: format-prettier | ||
format-prettier: | ||
./assets/node_modules/.bin/prettier --single-quote --write --no-bracket-spacing --print-width 130 './webapp/app/**/*.{js,gql}' | ||
|
||
# Development targets | ||
# ------------------- | ||
|
||
.PHONY: dev-start-postgresql | ||
dev-start-postgresql: ## Run a PostgreSQL server inside of a Docker Compose environment | ||
docker-compose up --detach postgresql | ||
|
||
.PHONY: dev-start-application | ||
dev-start-application: ## Run the OTP release inside of a Docker Compose environment | ||
docker-compose up application | ||
|
||
.PHONY: dev-start | ||
dev-start: ## Start every service of in the Docker Compose environment | ||
docker-compose up | ||
|
||
.PHONY: dev-stop | ||
dev-stop: ## Stop every service of in the Docker Compose environment | ||
docker-compose down |
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
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,6 +1,11 @@ | ||
use Mix.Config | ||
|
||
config :accent, Accent.Endpoint, check_origin: false | ||
config :accent, Accent.Endpoint, | ||
check_origin: false, | ||
server: true, | ||
root: ".", | ||
cache_static_manifest: "priv/static/cache_manifest.json" | ||
|
||
config :accent, dummy_provider_enabled: false | ||
|
||
config :logger, level: :info |
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,5 @@ | ||
{ | ||
"skip_files": [ | ||
"lib/accent/release_tasks.ex" | ||
] | ||
} |
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,24 @@ | ||
version: '3.3' | ||
services: | ||
application: | ||
image: accent | ||
container_name: accent | ||
ports: | ||
- 4000:4000 | ||
depends_on: | ||
- postgresql | ||
environment: | ||
- PORT=4000 | ||
- DATABASE_URL=postgres://postgres@postgresql:5432/accent_development | ||
- GOOGLE_API_CLIENT_ID=xxxxxxxx.apps.googleusercontent.com | ||
postgresql: | ||
image: postgres:10.3 | ||
container_name: accent-postgres | ||
environment: | ||
- POSTGRES_DB=accent_development | ||
ports: | ||
- 5432:5432 | ||
volumes: | ||
- accent_psql:/var/lib/postgresql/data | ||
volumes: | ||
accent_psql: |
Oops, something went wrong.