diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..727b8ab --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +dist +uploads +frontend/node_modules +internal/frontend/frontend_generated.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aac4558 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 567b259..a0fc374 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,27 @@ Currently you can do the following to tasks: ## 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 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` +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 This is a list of features that will eventually be added to Citadel in no particular order: diff --git a/conf/app.example.toml b/conf/app.example.toml index 5a3030a..3087bb3 100644 --- a/conf/app.example.toml +++ b/conf/app.example.toml @@ -11,10 +11,10 @@ storage_system = 'local_storage' upload_dir_path = 'uploads' [database] -host = '0.0.0.0' +host = 'postgres' name = 'citadel' -user = 'postgres' -password = 'test' +user = 'citadel' +password = 'citadel_test' [smtp] username = 'admin@example.com' diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..c06087c --- /dev/null +++ b/docker-compose.dev.yml @@ -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 diff --git a/docker-compose.migrate.yml b/docker-compose.migrate.yml new file mode 100644 index 0000000..194ec67 --- /dev/null +++ b/docker-compose.migrate.yml @@ -0,0 +1,12 @@ +version: '3' + +services: + migrate: + build: . + entrypoint: ./citadel migrate + volumes: + - ./migrations:/root/migrations + depends_on: + - postgres + networks: + - citadel-test diff --git a/docker-compose.yml b/docker-compose.yml index c06087c..c4868cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,29 @@ version: "3" services: - mailhog: - image: mailhog/mailhog:latest - restart: always + web: + build: . ports: - - 1025:1025 - - 8025:8025 - broker: - image: rabbitmq:3-management + - "3333:3333" + depends_on: + - postgres + networks: + - citadel-test + postgres: + image: postgres:12.3-alpine restart: always - ports: - - 8060:15672 - - 5672:5672 - result_store: - image: memcached:1.6-alpine - restart: always - ports: - - 11211:11211 + networks: + - citadel-test + environment: + POSTGRES_USER: citadel + POSTGRES_PASSWORD: citadel_test + POSTGRES_DB: citadel + volumes: + - citadel-postgres:/var/lib/postgresql/data + +volumes: + citadel-postgres: + external: false + +networks: + citadel-test: + driver: bridge diff --git a/magefile.go b/magefile.go index 8d43ac4..2b6cf9f 100644 --- a/magefile.go +++ b/magefile.go @@ -15,7 +15,8 @@ import ( ) var Aliases = map[string]interface{}{ - "s": Backend.Schema, + "s": Backend.Schema, + "up": Docker.Up, } type Frontend mg.Namespace @@ -77,6 +78,17 @@ func (Backend) Schema() error { func Install() { mg.SerialDeps(Frontend.Install) } + func 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") +}