Browse Source

Docs and better dockerfile

fixes #2
edit
Victor Roest 2 years ago
parent
commit
56a3fbdd3c
Signed by: 0x76 GPG Key ID: A3923C699D1A3BDA
  1. 16
      Dockerfile
  2. 77
      README.md
  3. 56
      deploy.md
  4. 8
      docs/screenshots.md
  5. BIN
      docs/screenshots/add_poem.png
  6. BIN
      docs/screenshots/index.png
  7. BIN
      docs/screenshots/poem.png

16
Dockerfile

@ -1,4 +1,4 @@
FROM elixir:1.11 AS builder
FROM elixir:1.11-alpine AS builder
ENV MIX_ENV=prod
@ -6,11 +6,11 @@ WORKDIR /build/dps
# Download + Compile dependencies
RUN mix local.rebar --force && mix local.hex --force
COPY mix.* .
COPY mix.exs mix.lock ./
COPY config config
RUN mix do deps.get, deps.compile
# Compile static assets
COPY config config
COPY priv/static priv/static
RUN mix phx.digest
@ -21,10 +21,16 @@ RUN mkdir -p /opt/release && \
mv _build/${MIX_ENV}/rel/dps /opt/release
# Runner image
FROM erlang:23 AS runner
FROM alpine:3 AS runner
RUN apk add --no-cache openssl ncurses-libs
WORKDIR /app/
ENV HOME=/app
RUN chown nobody:nobody /app
USER nobody:nobody
COPY --from=builder /opt/release/dps .
COPY --chown=nobody:nobody --from=builder /opt/release/dps .
CMD ["/app/bin/dps", "start"]

77
README.md

@ -1,10 +1,87 @@
# Poems
A minimalistic website to store and view my favourite poems.
An online version is hosted at <https://poems.xirion.net/>
For screenshots see [screenshots.md](./docs/screenshots.md)
## Development
Requirements:
* Docker (Optional, but very useful)
* Elixir and mix
To run dps in dev mode:
```bash
docker-compose up -d db # Start local postgres db inside a docker container
mix.ecto.reset # Migrate and seed the database
mix phx.server # Start the live reload server
```
For running the tests simply do
```bash
# Start db if it isn't running already
docker-compose up -d db
# Run tests
mix test
```
## Deployment
Some notes on how to deploy The application.
### K8s Deployment (recommended)
For deploying on k8s the files in `k8s` give an example of how to do so.
Make sure to set the FQDNs and the env vars correctly.
### Docker deployment
To deploy in docker you can use `docker-compose.yml` like so.
```bash
# Build the container
docker build . -t dps
# Start the docker-compose db
docker-compose up -d db
# Setup schema
mix ecto.reset
# Start dps itself
docker-compose up -d dps
# Verify its working
curl localhost:4000
```
### Running locally
To run the application locally in release mode do the following:
```bash
# Generate static digests (make sure to not commit these)
mix phx.digest
# Build the release
MIX_ENV=prod mix release
# Ensure database is populated
mix ecto.reset
# Run the program with correct parameters
DATABASE_URL=ecto://postgres:postgres@localhost/dps_prod \
RELEASE_COOKIE=secret-cookie \
SECRET_KEY_BASE=kZ3O750w/sd7CcXO9053xWGTlOW3dYtLORLiYKqOL25UwboP/TJZz5g+YhOVLzOy \
HOSTNAME=127.0.0.1 \
SERVICE_NAME=localhost.svc \
APP_HOST=localhost \
APP_PORT=4000 \
AUTH_USERNAME=user \
AUTH_PASSWORD=pass \
PORT=4000 \
_build/prod/rel/dps/bin/dps start
```
#### Deployment References
* [Elixir + Kubernetes = 💜 by Drew Cain](https://medium.com/@groksrc/elixir-plus-kubernetes-part-1-80129eab14f0)
* [Upcoming phoenix runtime config](https://github.com/phoenixframework/phoenix/pull/4040)
* [Phoenix Deployment Docs](https://hexdocs.pm/phoenix/deployment.html)

56
deploy.md

@ -1,56 +0,0 @@
# Deployment notes
Some notes on how to deploy this application and how the deployment configuration works
## K8s Deployment
For deploying on k8s the files in `k8s` give an example of how to do so.
Make sure to set the FQDNs and the env vars correctly.
## Smoke Test Release
To smoke test the application in release mode do the following:
```bash
# Generate static digests (make sure to not commit these)
mix phx.digest
# Build the release
MIX_ENV=prod mix release
# Ensure database is populated
mix ecto.reset
# Run the program with dev parameters
DATABASE_URL=ecto://postgres:postgres@localhost/dps_dev \
RELEASE_COOKIE=secret-cookie \
SECRET_KEY_BASE=kZ3O750w/sd7CcXO9053xWGTlOW3dYtLORLiYKqOL25UwboP/TJZz5g+YhOVLzOy \
HOSTNAME=127.0.0.1 \
SERVICE_NAME=localhost.svc \
APP_HOST=localhost \
APP_PORT=4000 \
AUTH_USERNAME=user \
AUTH_PASSWORD=pass \
PORT=4000 \
_build/prod/rel/dps/bin/dps start
```
## Smoke test docker
```bash
# first make sure no postgres container is running
mix postgres stop
# Start the docker-compose db
docker-compose up -d db
# Setup schema
mix ecto.reset
# Start dps itself
docker-compose up -d dps
# Verify its working
curl localhost:4000/api/poems | jq
```
## References
* [Elixir + Kubernetes = 💜 by Drew Cain](https://medium.com/@groksrc/elixir-plus-kubernetes-part-1-80129eab14f0)
* [Upcoming phoenix runtime config](https://github.com/phoenixframework/phoenix/pull/4040)

8
docs/screenshots.md

@ -0,0 +1,8 @@
#### Homepage
![](./screenshots/index.png)
#### Poem
![](./screenshots/poem.png)
#### Add Poem
![](./screenshots/add_poem.png)

BIN
docs/screenshots/add_poem.png (Stored with Git LFS)

Binary file not shown.

BIN
docs/screenshots/index.png (Stored with Git LFS)

Binary file not shown.

BIN
docs/screenshots/poem.png (Stored with Git LFS)

Binary file not shown.
Loading…
Cancel
Save