feature: add Dockerfile & docker-compose installation instructions

This commit is contained in:
Jordan Knott 2020-07-18 17:28:25 -05:00
parent de03fd9ef7
commit 66a2931ab8
8 changed files with 124 additions and 19 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
.git
dist
uploads
frontend/node_modules
internal/frontend/frontend_generated.go

18
Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM node:14.5-alpine as frontend
RUN apk --no-cache add curl
WORKDIR /usr/src/app
COPY frontend .
RUN yarn install
RUN yarn build
FROM golang:1.14.5-alpine as backend
WORKDIR /usr/src/app
COPY . .
COPY --from=frontend /usr/src/app/build .
RUN go run cmd/mage/main.go backend:genFrontend backend:build
FROM alpine:latest
WORKDIR /root/
COPY --from=backend /usr/src/app/dist/citadel .
COPY --from=backend /usr/src/app/conf/app.example.toml conf/app.toml
CMD ["./citadel", "web"]

View File

@ -21,6 +21,27 @@ Currently you can do the following to tasks:
## Installation ## Installation
### With docker & docker-compose
You'll need both [docker](https://www.docker.com/) & [docker-compose](https://docs.docker.com/compose/install/) installed.
You will also need to install [Mage](https://github.com/magefile/mage/releases) or if you have Go installed already
you can replace the `mage` command below with `go run cmd/mage/main.go`.
Now do the following:
``` bash
mage up
mage docker:migrate
```
This will start a postgres instance as well as a citadel instance.
The second command runs the database shema migrations.
If you visit [http://localhost:3333](http://localhost:3333), you will get redirected to the installation
screen so that you can create the first system user.
### From Source ### From Source
You'll need [Golang](https://golang.org/dl/) installed on your machine. You'll need [Golang](https://golang.org/dl/) installed on your machine.
@ -49,6 +70,14 @@ The newly created `citadel` binary can be found in the __dist__ folder.
It contains everything neccessary to run except the config file. An example config file can be found in `conf/app.example.toml` It contains everything neccessary to run except the config file. An example config file can be found in `conf/app.example.toml`
The config will need to be copied to a `conf/app.toml` in the same place the binary is.
Make sure to fill out the database section of the config in order to connect it to your database.
Then run the database migrations with `citadel migrate`.
Now you can run the web interface by running `citadel web`
## Roadmap ## Roadmap
This is a list of features that will eventually be added to Citadel in no particular order: This is a list of features that will eventually be added to Citadel in no particular order:

View File

@ -11,10 +11,10 @@ storage_system = 'local_storage'
upload_dir_path = 'uploads' upload_dir_path = 'uploads'
[database] [database]
host = '0.0.0.0' host = 'postgres'
name = 'citadel' name = 'citadel'
user = 'postgres' user = 'citadel'
password = 'test' password = 'citadel_test'
[smtp] [smtp]
username = 'admin@example.com' username = 'admin@example.com'

19
docker-compose.dev.yml Normal file
View File

@ -0,0 +1,19 @@
version: "3"
services:
mailhog:
image: mailhog/mailhog:latest
restart: always
ports:
- 1025:1025
- 8025:8025
broker:
image: rabbitmq:3-management
restart: always
ports:
- 8060:15672
- 5672:5672
result_store:
image: memcached:1.6-alpine
restart: always
ports:
- 11211:11211

View File

@ -0,0 +1,12 @@
version: '3'
services:
migrate:
build: .
entrypoint: ./citadel migrate
volumes:
- ./migrations:/root/migrations
depends_on:
- postgres
networks:
- citadel-test

View File

@ -1,19 +1,29 @@
version: "3" version: "3"
services: services:
mailhog: web:
image: mailhog/mailhog:latest build: .
restart: always
ports: ports:
- 1025:1025 - "3333:3333"
- 8025:8025 depends_on:
broker: - postgres
image: rabbitmq:3-management networks:
- citadel-test
postgres:
image: postgres:12.3-alpine
restart: always restart: always
ports: networks:
- 8060:15672 - citadel-test
- 5672:5672 environment:
result_store: POSTGRES_USER: citadel
image: memcached:1.6-alpine POSTGRES_PASSWORD: citadel_test
restart: always POSTGRES_DB: citadel
ports: volumes:
- 11211:11211 - citadel-postgres:/var/lib/postgresql/data
volumes:
citadel-postgres:
external: false
networks:
citadel-test:
driver: bridge

View File

@ -16,6 +16,7 @@ import (
var Aliases = map[string]interface{}{ var Aliases = map[string]interface{}{
"s": Backend.Schema, "s": Backend.Schema,
"up": Docker.Up,
} }
type Frontend mg.Namespace type Frontend mg.Namespace
@ -77,6 +78,17 @@ func (Backend) Schema() error {
func Install() { func Install() {
mg.SerialDeps(Frontend.Install) mg.SerialDeps(Frontend.Install)
} }
func Build() { func Build() {
mg.SerialDeps(Frontend.Build, Backend.GenFrontend, Backend.Build) mg.SerialDeps(Frontend.Build, Backend.GenFrontend, Backend.Build)
} }
type Docker mg.Namespace
func (Docker) Up() error {
return sh.RunV("docker-compose", "-p", "citadel", "up", "-d")
}
func (Docker) Migrate() error {
return sh.RunV("docker-compose", "-p", "citadel", "-f", "docker-compose.yml", "-f", "docker-compose.migrate.yml", "run", "--rm", "migrate")
}