Skip to content

Commit

Permalink
Refine release process docker (#45)
Browse files Browse the repository at this point in the history
* build: Enable multi-stage Dockerfile

* build: Optimize docker-compose for developer

* build: Expose port of postgres in docker-compose.yml

* build: Extended Dockerfile to include develop and prod build with multistages

* ci: 🔧 Add new github action workflow for automated release

* docs: Adjusted README to document development

* docs: Added installation guide for different production setups
  • Loading branch information
gerardo-navarro authored Feb 16, 2021
1 parent 0d7e8c9 commit 624aee4
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 60 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
READMETEMPLATE.md
README.md

# git
.git
**/.git
.gitattributes
.gitignore

# Node
## Logs
logs
*.log
assets/npm-debug.log*
assets/yarn-debug.log*
assets/yarn-error.log*

## Dependency directories
assets/node_modules/

## Misc files
.tool_versions
elixir_buildpack.config
phoenix_static_buildpack.config
README.md
LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Do not forget to change status badge in ./README.md
name: ci_cd
name: on_push_branch__execute_ci_cd

on:
push:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/on_push_tag__build_publish_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: on_push_tag_build_publish_release

on:
workflow_dispatch:
docker_tag:
description: "Define the docker tag name. You can define the docker tag version separately"
default: mindwendel
docker_tag_version:
description: "Define the docker tag version"
required: true
push:
tags:
- "*.*.*"

jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Setting vars for later access
id: set_vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Check out the repo
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_CONTAINER_REGISTRY_PERSONAL_ACCESS_TOKEN }}

- name: Push to GitHub Packages
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ format('ghcr.io/mindwendel/mindwendel:{0}', steps.set_vars.outputs.tag) }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
22 changes: 0 additions & 22 deletions .github/workflows/publish_docker.yml

This file was deleted.

57 changes: 48 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
FROM elixir:1.11-alpine

RUN apk add --update-cache \
postgresql-client \
nodejs npm
ARG ALPINE_VERSION=3.13

FROM elixir:1.11-alpine as elixir_alpine

RUN apk add --update-cache postgresql-client nodejs npm

RUN mix do local.hex --force, local.rebar --force

WORKDIR /app

COPY . .
RUN mix local.hex --force
RUN mix local.rebar --force
RUN mix deps.get

FROM elixir_alpine as development

RUN mix do deps.get, compile
RUN npm --prefix assets install
RUN mix compile

RUN ["chmod", "+x", "./entrypoint.sh"]
ENTRYPOINT ["sh", "./entrypoint.sh"]
ENTRYPOINT ["sh", "./entrypoint.sh"]


# Building a release version
# https://hexdocs.pm/phoenix/releases.html
FROM elixir_alpine AS build

# Set build ENV
ENV MIX_ENV=prod

# Install mix dependencies
RUN mix do deps.get, deps.compile

# Build assets
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
RUN npm run --prefix ./assets deploy
RUN mix phx.digest

# compile and build release
RUN mix do compile, release

# prepare release image
FROM alpine:${ALPINE_VERSION} AS app
RUN apk add --no-cache openssl ncurses-libs postgresql-client

WORKDIR /app

RUN chown nobody:nobody /app

USER nobody:nobody

COPY entrypoint.release.sh /app/entrypoint.release.sh
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/mindwendel ./

ENV HOME=/app

ENTRYPOINT ["sh", "./entrypoint.release.sh"]
86 changes: 60 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Create a challenge. Ready? Brainstorm. mindwendel helps you to easily brainstorm and upvote ideas and thoughts within your team. Built from scratch with [Phoenix](https://www.phoenixframework.org).

## Features
- Anonymously invite people to your brainstorming - no registration needed. Usernames are optional.

- 5 minute setup (It is not a joke)
- Anonymously invite people to your brainstormings - no registration needed. Usernames are optional.
- Easily create and upvote ideas, with live updates from your companions.
- Preview of links to ease URL sharing
- Cluster your ideas with labels
Expand All @@ -15,22 +17,69 @@ Create a challenge. Ready? Brainstorm. mindwendel helps you to easily brainstorm
![](docs/screenshot2.png)

## Use-cases

Brainstorm ...

- ... new business ideas
- ... solutions for a problem
- ... what to eat tonight
- ...
- ...

## Getting Started

### Prerequisites
mindwendel can be run just about anywhere. So checkout our [Installation Guides](./docs/installing_mindwendel.md) for detailed instructions for various deployments.

Here's the TLDR:

- Run mindwendel via Docker and reference your postgres database

```sh
docker run -d --name mindwendel \
-p 127.0.0.1:80:4000 \
-e DATABASE_HOST="..." \
-e DATABASE_PORT="5432" \
-e DATABASE_NAME="mindwendel_prod" \
-e DATABASE_USER="mindwendel_db_user" \
-e DATABASE_USER_PASSWORD="mindwendel_db_user_password" \
-e SECRET_KEY_BASE="generate_your_own_secret_key_base_and_save_it" \
-e URL_HOST="your_domain_to_mindwendel" \
ghcr.io/mindwendel/mindwendel
```

NOTE: mindwendel requires a postgres database. You can use [our docker-compose file](./docs/installing_mindwendel.md#running-on-docker-compose) to also install the postgres.

## Usage example

## Contributing

To get started with a development installation of mindwendel, follow the instructions below.

mindwendel is built on top of:

- [Elixir](https://elixir-lang.org/install.html)
- [Phoenix Framework](https://hexdocs.pm/phoenix/installation.html#phoenix)
- [Phoenix LiveView](https://github.com/phoenixframework/phoenix_live_view)
- [PostgreSQL](https://www.postgresql.org)

### For local setup and development
### Dev setup based on Docker

- Startup docker container
```sh
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
```
- Go to http://localhost:4000/

- Open you favorite editor and start developing

- Open a shell in the docker container to execute tests, etc.

```sh
docker exec -it mindwendel sh
```

- In the shell, you can now execute all commands as on you local machine, see [testing commands](#testing)

### Dev setup an your local machine (without docker)

- Clone the repo
```sh
Expand Down Expand Up @@ -66,28 +115,6 @@ Brainstorm ...
```
- Go to http://localhost:4000/

### For docker development

```sh
docker-compose build
```

```sh
docker-compose up
```

To browse the container, use e.g.:

```sh
docker exec -it mindwendel sh
```

## Usage example

## Development setup

For local development, please follow [the guide for local development setup](#for-local-setup-and-development).

### Testing

- Load the env variables for testing
Expand All @@ -103,6 +130,13 @@ For local development, please follow [the guide for local development setup](#fo
mix test
```

### Build release and production docker image

- Build the docker image based on our Dockerfile
```sh
docker build -t mindwendel_prod .
```

### Formatting

We are using Elixir's built-in formatter.
Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version: '3'
version: "3"

services:
mindwendel:
container_name: mindwendel
build:
context: .
target: development
environment:
DATABASE_USER: postgres
DATABASE_USER_PASSWORD: postgres
Expand All @@ -24,13 +25,17 @@ services:
# In case you want to use the included .env file to provide the credentials.
# env_file:
# - .env

db:
image: postgres:latest
environment:
# IMPORTANT: Do not use these credentials in produciton. Please use other credentials when deploying this in production
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGDATA: /var/lib/postgresql/data/pgdata
restart: always
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
Expand Down
Loading

0 comments on commit 624aee4

Please sign in to comment.