Merge pull request #4151 from Ocelot-Social-Community/fix_docker

Rework dockerfiles & docker-compose
This commit is contained in:
Ulf Gebhardt 2021-01-28 17:14:12 +01:00 committed by GitHub
commit 5ef781c49d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 508 additions and 323 deletions

View File

@ -15,32 +15,78 @@ jobs:
scripts/translations/sort.sh scripts/translations/sort.sh
scripts/translations/missing-keys.sh scripts/translations/missing-keys.sh
- name: Build neo4j image ##########################################################################
# NEO4J ##################################################################
##########################################################################
- name: Neo4J | Build `community` image
uses: docker/build-push-action@v1.1.0 uses: docker/build-push-action@v1.1.0
with: with:
repository: ocelotsocialnetwork/neo4j repository: ocelotsocialnetwork/neo4j
tags: latest tags: latest
path: neo4j/ path: neo4j/
push: false push: false
- name: Build backend base image
##########################################################################
# BACKEND ################################################################
##########################################################################
# TODO: We want to push this to dockerhub
#- name: Build backend production image
# uses: docker/build-push-action@v1.1.0
# with:
# repository: ocelotsocialnetwork/backend
# tags: production
# target: production
# path: backend/
# push: false
# Build Docker Image (build)
- name: backend | Build `build` image
uses: docker/build-push-action@v1.1.0 uses: docker/build-push-action@v1.1.0
with: with:
repository: ocelotsocialnetwork/backend repository: ocelotsocialnetwork/backend
tags: build-and-test tags: build
target: build-and-test target: build
path: backend/ path: backend/
push: false push: false
- name: Build webapp base image
# Lint
- name: backend | Lint
run: docker run --rm ocelotsocialnetwork/backend:build yarn run lint
# Unit Tests
#- name: backend | Unit tests
# run: |
# docker-compose up
# docker-compose exec backend yarn test
##########################################################################
# WEBAPP #################################################################
##########################################################################
# TODO: We want to push this to dockerhub
#- name: Build webapp production image
# uses: docker/build-push-action@v1.1.0
# with:
# repository: ocelotsocialnetwork/webapp
# tags: production
# target: production
# path: webapp/
# push: false
# Build Docker Image (build)
- name: webapp | Build `build` image
uses: docker/build-push-action@v1.1.0 uses: docker/build-push-action@v1.1.0
with: with:
repository: ocelotsocialnetwork/webapp repository: ocelotsocialnetwork/webapp
tags: build-and-test tags: build
target: build-and-test target: build
path: webapp/ path: webapp/
push: false push: false
- name: Lint backend # Lint
run: docker run --rm ocelotsocialnetwork/backend:build-and-test yarn run lint - name: webapp | Lint
- name: Lint webapp run: docker run --rm ocelotsocialnetwork/webapp:build yarn run lint
run: docker run --rm ocelotsocialnetwork/webapp:build-and-test yarn run lint
# Unit Tests
- name: webapp | Unit tests
run: docker run --rm ocelotsocialnetwork/webapp:build yarn run test

100
README.md
View File

@ -1,4 +1,4 @@
# Human-Connection # ocelot.social
[![Build Status](https://travis-ci.com/Human-Connection/Human-Connection.svg?branch=master)](https://travis-ci.com/Human-Connection/Human-Connection) [![Build Status](https://travis-ci.com/Human-Connection/Human-Connection.svg?branch=master)](https://travis-ci.com/Human-Connection/Human-Connection)
[![Codecov Coverage](https://img.shields.io/codecov/c/github/Human-Connection/Human-Connection/master.svg?style=flat-square)](https://codecov.io/gh/Human-Connection/Human-Connection/) [![Codecov Coverage](https://img.shields.io/codecov/c/github/Human-Connection/Human-Connection/master.svg?style=flat-square)](https://codecov.io/gh/Human-Connection/Human-Connection/)
@ -6,22 +6,13 @@
[![Discord Channel](https://img.shields.io/discord/489522408076738561.svg)](https://discordapp.com/invite/DFSjPaX) [![Discord Channel](https://img.shields.io/discord/489522408076738561.svg)](https://discordapp.com/invite/DFSjPaX)
[![Open Source Helpers](https://www.codetriage.com/human-connection/human-connection/badges/users.svg)](https://www.codetriage.com/human-connection/human-connection) [![Open Source Helpers](https://www.codetriage.com/human-connection/human-connection/badges/users.svg)](https://www.codetriage.com/human-connection/human-connection)
Human Connection is a nonprofit social, action and knowledge network that connects information to action and promotes positive local and global change in all areas of life. ocelot.social is a nonprofit social, action and knowledge network that connects information to action and promotes positive local and global change in all areas of life.
* **Social**: Interact with other people not just by commenting their posts, but by providing **Pro & Contra** arguments, give a **Versus** or ask them by integrated **Chat** or **Let's Talk** * **Social**: Interact with other people not just by commenting their posts, but by providing **Pro & Contra** arguments, give a **Versus** or ask them by integrated **Chat** or **Let's Talk**
* **Knowledge**: Read articles about interesting topics and find related posts in the **More Info** tab or by **Filtering** based on **Categories** and **Tagging** or by using the **Fulltext Search**. * **Knowledge**: Read articles about interesting topics and find related posts in the **More Info** tab or by **Filtering** based on **Categories** and **Tagging** or by using the **Fulltext Search**.
* **Action**: Don't just read about how to make the world a better place, but come into **Action** by following provided suggestions on the **Action** tab provided by other people or **Organisations**. * **Action**: Don't just read about how to make the world a better place, but come into **Action** by following provided suggestions on the **Action** tab provided by other people or **Organisations**.
[![Human-Connection](.gitbook/assets/lets_get_together.png)](https://human-connection.org) [![Ocelot-Social](webapp/static/img/custom/welcome.svg)](https://ocelot.social)
**Technology Stack**
* [VueJS](https://vuejs.org/)
* [NuxtJS](https://nuxtjs.org/)
* [GraphQL](https://graphql.org/)
* [NodeJS](https://nodejs.org/en/)
* [Neo4J](https://neo4j.com/)
## Live demo ## Live demo
@ -35,14 +26,77 @@ Logins:
| `moderator@example.org` | 1234 | moderator | | `moderator@example.org` | 1234 | moderator |
| `admin@example.org` | 1234 | admin | | `admin@example.org` | 1234 | admin |
## Documentation ## Directory Layout
Learn how to set up a local development environment in our [Docs](https://docs.human-connection.org/human-connection/) :mag_right: There are four important directories:
* [Backend](./backend) runs on the server and is a middleware between database and frontend
* [Frontend](./webapp) is a server-side-rendered and client-side-rendered web frontend
* [Deployment](./deployment) configuration for kubernetes
* [Cypress](./cypress) contains end-to-end tests and executable feature specifications
## Translations In order to setup the application and start to develop features you have to
setup **frontend** and **backend**.
You can help translating the interface by joining us on [lokalise.co](https://lokalise.co/public/556252725c18dd752dd546.13222042/). There are two approaches:
Thank you lokalise for providing us with a premium account :raised_hands:.
1. Local installation, which means you have to take care of dependencies yourself
2. **Or** Install everything through Docker which takes care of dependencies for you
## Installation
### Clone the Repository
Clone the repository, this will create a new folder called `Ocelot-Social`:
Using HTTPS:
```bash
$ git clone https://github.com/Ocelot-Social-Community/Ocelot-Social.git
```
Using SSH:
```bash
$ git clone git@github.com:Human-Connection/Human-Connection.git
```
Change into the new folder.
```bash
$ cd Ocelot-Social
```
### Docker Installation
Docker is a software development container tool that combines software and its dependencies into one standardized unit that contains everything needed to run it. This helps us to avoid problems with dependencies and makes installation easier.
#### General Installation of Docker
There are [sevaral ways to install Docker CE](https://docs.docker.com/install/) on your computer or server.
* [install Docker Desktop on macOS](https://docs.docker.com/docker-for-mac/install/)
* [install Docker Desktop on Windows](https://docs.docker.com/docker-for-windows/install/)
* [install Docker CE on Linux](https://docs.docker.com/install/)
Check the correct Docker installation by checking the version before proceeding. E.g. we have the following versions:
```bash
$ docker --version
Docker version 18.09.2
$ docker-compose --version
docker-compose version 1.23.2
```
#### Start Ocelot-Social via Docker-Compose
For Development:
```bash
docker-compose up
```
For Production
```bash
docker-compose -f docker-compose.yml up
```
This will start all required Docker containers
## Developer Chat ## Developer Chat
@ -50,12 +104,16 @@ Join our friendly open-source community on [Discord](https://discordapp.com/invi
Just introduce yourself at `#introduce-yourself` and mention `@@Mentor` to get you onboard :neckbeard: Just introduce yourself at `#introduce-yourself` and mention `@@Mentor` to get you onboard :neckbeard:
Check out the [contribution guideline](./CONTRIBUTING.md), too! Check out the [contribution guideline](./CONTRIBUTING.md), too!
[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/0)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/0)[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/1)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/1)[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/2)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/2)[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/3)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/3)[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/4)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/4)[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/5)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/5)[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/6)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/6)[![](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/images/7)](https://sourcerer.io/fame/roschaefer/Human-Connection/Human-Connection/links/7) We give write permissions to every developer who asks for it. Just text us on
[Discord](https://discord.gg/6ub73U3).
## Open-Source Bounties ## Technology Stack
You can get a small financial compensation for your contribution :moneybag: See * [VueJS](https://vuejs.org/)
details in our [Contribution Guidelines](./CONTRIBUTING.md#open-source-bounties). * [NuxtJS](https://nuxtjs.org/)
* [GraphQL](https://graphql.org/)
* [NodeJS](https://nodejs.org/en/)
* [Neo4J](https://neo4j.com/)
## Attributions ## Attributions

View File

@ -2,7 +2,6 @@
* [Introduction](README.md) * [Introduction](README.md)
* [Edit this Documentation](edit-this-documentation.md) * [Edit this Documentation](edit-this-documentation.md)
* [Installation](installation.md)
* [Neo4J](neo4j/README.md) * [Neo4J](neo4j/README.md)
* [Backend](backend/README.md) * [Backend](backend/README.md)
* [GraphQL](backend/graphql.md) * [GraphQL](backend/graphql.md)

View File

@ -1,28 +1,87 @@
##################################################################################
# BASE ###########################################################################
##################################################################################
FROM node:12.19.0-alpine3.10 as base FROM node:12.19.0-alpine3.10 as base
LABEL Description="Backend of the Social Network ocelot.social" Vendor="ocelot.social Community" Version="0.0.1" Maintainer="ocelot.social Community (devops@ocelot.social)"
EXPOSE 4000 # ENVs (available in production aswell, can be overwritten by commandline or env file)
CMD ["yarn", "run", "start"] ## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame
ARG BUILD_COMMIT ENV DOCKER_WORKDIR="/app"
ENV BUILD_COMMIT=$BUILD_COMMIT ## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0
ARG WORKDIR=/develop-backend ENV BUILD_DATE="1970-01-01T00:00:00.00Z"
RUN mkdir -p $WORKDIR ## We cannot do $(yarn run version) here so we default to 0.0.0
WORKDIR $WORKDIR ## TODO: Missing Build number - do that once we have a CI which actually generates it
ENV BUILD_VERSION="0.0.0"
## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000
ENV BUILD_COMMIT="0000000"
## SET NODE_ENV
ENV NODE_ENV="production"
## App relevant Envs
ENV PORT="4000"
# Labels
LABEL org.label-schema.build-date="${BUILD_DATE}"
LABEL org.label-schema.name="ocelot.social:backend"
LABEL org.label-schema.description="Backend of the Social Network Software ocelot.social"
LABEL org.label-schema.usage="https://github.com/Ocelot-Social-Community/Ocelot-Social/blob/master/README.md"
LABEL org.label-schema.url="https://ocelot.social"
LABEL org.label-schema.vcs-url="https://github.com/Ocelot-Social-Community/Ocelot-Social/tree/master/backend"
LABEL org.label-schema.vcs-ref="${BUILD_COMMIT}"
LABEL org.label-schema.vendor="ocelot.social Community"
LABEL org.label-schema.version="${BUILD_VERSION}"
LABEL org.label-schema.schema-version="1.0"
LABEL maintainer="devops@ocelot.social"
# Install Additional Software
## install: git
RUN apk --no-cache add git RUN apk --no-cache add git
COPY package.json yarn.lock ./ # Settings
COPY .env.template .env ## Expose Container Port
EXPOSE ${PORT}
FROM base as build-and-test ## Workdir
RUN yarn install --production=false --frozen-lockfile --non-interactive RUN mkdir -p ${DOCKER_WORKDIR}
WORKDIR ${DOCKER_WORKDIR}
##################################################################################
# DEVELOPMENT (Connected to the local environment, to reload on demand) ##########
##################################################################################
FROM base as development
# We don't need to copy or build anything since we gonna bind to the
# local filesystem which will need a rebuild anyway
# Run command
# (for development we need to execute yarn install since the
# node_modules are on another volume and need updating)
CMD /bin/sh -c "yarn install && yarn run dev"
##################################################################################
# BUILD (Does contain all files and is therefore bloated) ########################
##################################################################################
FROM base as build
# Copy everything
COPY . . COPY . .
RUN NODE_ENV=production yarn run build # yarn install
RUN yarn install --production=false --frozen-lockfile --non-interactive
# yarn build
RUN yarn run build
# reduce image size with a multistage build ##################################################################################
# PRODUCTION (Does contain only "binary"- and static-files to reduce image size) #
##################################################################################
FROM base as production FROM base as production
ENV NODE_ENV=production
COPY --from=build-and-test /develop-backend/dist ./dist # Copy "binary"-files from build image
COPY ./public/img/ ./public/img/ COPY --from=build ${DOCKER_WORKDIR}/dist ./dist
COPY ./public/providers.json ./public/providers.json COPY --from=build ${DOCKER_WORKDIR}/node_modules ./node_modules
RUN yarn install --production=true --frozen-lockfile --non-interactive --no-cache # Copy static files
# TODO - externalize the uploads so we can copy the whole folder
COPY --from=build ${DOCKER_WORKDIR}/public/img/ ./public/img/
COPY --from=build ${DOCKER_WORKDIR}/public/providers.json ./public/providers.json
# Copy package.json for script definitions (lock file should not be needed)
COPY --from=build ${DOCKER_WORKDIR}/package.json ./package.json
# Run command
CMD /bin/sh -c "yarn run start"

View File

@ -178,32 +178,20 @@ database after each test, running the tests will wipe out all your data!
{% tabs %} {% tabs %}
{% tab title="Docker" %} {% tab title="Docker" %}
Run the _**jest**_ tests: Run the unit tests:
```bash ```bash
$ docker-compose exec backend yarn run test:jest $ docker-compose exec backend yarn run test
```
Run the _**cucumber**_ features:
```bash
$ docker-compose exec backend yarn run test:cucumber
``` ```
{% endtab %} {% endtab %}
{% tab title="Without Docker" %} {% tab title="Without Docker" %}
Run the _**jest**_ tests: Run the unit tests:
```bash ```bash
$ yarn run test:jest $ yarn run test
```
Run the _**cucumber**_ features:
```bash
$ yarn run test:cucumber
``` ```
{% endtab %} {% endtab %}

View File

@ -15,7 +15,7 @@
"dev": "nodemon --exec babel-node src/ -e js,gql", "dev": "nodemon --exec babel-node src/ -e js,gql",
"dev:debug": "nodemon --exec babel-node --inspect=0.0.0.0:9229 src/ -e js,gql", "dev:debug": "nodemon --exec babel-node --inspect=0.0.0.0:9229 src/ -e js,gql",
"lint": "eslint src --config .eslintrc.js", "lint": "eslint src --config .eslintrc.js",
"test": "jest --forceExit --detectOpenHandles --runInBand", "test": "cross-env NODE_ENV=test jest --forceExit --detectOpenHandles --runInBand",
"db:clean": "babel-node src/db/clean.js", "db:clean": "babel-node src/db/clean.js",
"db:reset": "yarn run db:clean", "db:reset": "yarn run db:clean",
"db:seed": "babel-node src/db/seed.js", "db:seed": "babel-node src/db/seed.js",

View File

@ -1,6 +1,7 @@
import { handler } from './webfinger' import { handler } from './webfinger'
import Factory, { cleanDatabase } from '../../db/factories' import Factory, { cleanDatabase } from '../../db/factories'
import { getDriver } from '../../db/neo4j' import { getDriver } from '../../db/neo4j'
import CONFIG from '../../config'
let resource, res, json, status, contentType let resource, res, json, status, contentType
@ -98,12 +99,12 @@ describe('webfinger', () => {
expect(json).toHaveBeenCalledWith({ expect(json).toHaveBeenCalledWith({
links: [ links: [
{ {
href: 'http://localhost:3000/activitypub/users/some-user', href: `${CONFIG.CLIENT_URI}/activitypub/users/some-user`,
rel: 'self', rel: 'self',
type: 'application/activity+json', type: 'application/activity+json',
}, },
], ],
subject: 'acct:some-user@localhost:3000', subject: `acct:some-user@${new URL(CONFIG.CLIENT_URI).host}`,
}) })
}) })
}) })

View File

@ -8,7 +8,7 @@ if (require.resolve) {
dotenv.config({ path: require.resolve('../../.env') }) dotenv.config({ path: require.resolve('../../.env') })
} catch (error) { } catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') throw error if (error.code !== 'MODULE_NOT_FOUND') throw error
console.log('WARN: No `.env` file found in /backend') // eslint-disable-line no-console console.log('WARN: No `.env` file found in `/app` (docker) or `/backend` (no docker)') // eslint-disable-line no-console
} }
} }

View File

@ -29,15 +29,25 @@ const onlyYourself = rule({
const isMyOwn = rule({ const isMyOwn = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (parent, args, context, info) => { })(async (parent, args, { user }, info) => {
return context.user.id === parent.id return user && user.id === parent.id
}) })
const isMySocialMedia = rule({ const isMySocialMedia = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_, args, { user }) => { })(async (_, args, { user }) => {
// We need a User
if (!user) {
return false
}
let socialMedia = await neode.find('SocialMedia', args.id) let socialMedia = await neode.find('SocialMedia', args.id)
socialMedia = await socialMedia.toJson() // Did we find a social media node?
if (!socialMedia) {
return false
}
socialMedia = await socialMedia.toJson() // whats this for?
// Is it my social media entry?
return socialMedia.ownedBy.node.id === user.id return socialMedia.ownedBy.node.id === user.id
}) })

View File

@ -7,13 +7,13 @@ dbInitializion: "yarn prod:migrate init"
# dbMigrations runs the database migrations in a post-upgrade hook. # dbMigrations runs the database migrations in a post-upgrade hook.
dbMigrations: "yarn prod:migrate up" dbMigrations: "yarn prod:migrate up"
# bakendImage is the docker image for the backend deployment # bakendImage is the docker image for the backend deployment
backendImage: ocelotsocialnetwork/develop-backend backendImage: ocelotsocialnetwork/backend
# maintenanceImage is the docker image for the maintenance deployment # maintenanceImage is the docker image for the maintenance deployment
maintenanceImage: ocelotsocialnetwork/develop-maintenance maintenanceImage: ocelotsocialnetwork/maintenance
# neo4jImage is the docker image for the neo4j deployment # neo4jImage is the docker image for the neo4j deployment
neo4jImage: ocelotsocialnetwork/develop-neo4j neo4jImage: ocelotsocialnetwork/neo4j
# webappImage is the docker image for the webapp deployment # webappImage is the docker image for the webapp deployment
webappImage: ocelotsocialnetwork/develop-webapp webappImage: ocelotsocialnetwork/webapp
# image configures pullPolicy related to the docker images # image configures pullPolicy related to the docker images
image: image:
# pullPolicy indicates when, if ever, pods pull a new image from docker hub. # pullPolicy indicates when, if ever, pods pull a new image from docker hub.

View File

@ -43,13 +43,13 @@ Then temporarily delete backend and database deployments
```bash ```bash
$ kubectl -n ocelot-social get deployments $ kubectl -n ocelot-social get deployments
NAME READY UP-TO-DATE AVAILABLE AGE NAME READY UP-TO-DATE AVAILABLE AGE
develop-backend 1/1 1 1 3d11h backend 1/1 1 1 3d11h
develop-neo4j 1/1 1 1 3d11h neo4j 1/1 1 1 3d11h
develop-webapp 2/2 2 2 73d webapp 2/2 2 2 73d
$ kubectl -n ocelot-social delete deployment develop-neo4j $ kubectl -n ocelot-social delete deployment neo4j
deployment.extensions "develop-neo4j" deleted deployment.extensions "neo4j" deleted
$ kubectl -n ocelot-social delete deployment develop-backend $ kubectl -n ocelot-social delete deployment backend
deployment.extensions "develop-backend" deleted deployment.extensions "backend" deleted
``` ```
Deploy one-time develop-maintenance-worker pod: Deploy one-time develop-maintenance-worker pod:

View File

@ -18,8 +18,8 @@ minikube dashboard, expose the services you want on your host system.
For example: For example:
```text ```text
$ minikube service develop-webapp --namespace=ocelotsocialnetwork $ minikube service webapp --namespace=ocelotsocialnetwork
# optionally # optionally
$ minikube service develop-backend --namespace=ocelotsocialnetwork $ minikube service backend --namespace=ocelotsocialnetwork
``` ```

View File

@ -37,7 +37,7 @@ spec:
name: configmap name: configmap
- secretRef: - secretRef:
name: ocelot-social name: ocelot-social
image: ocelotsocialnetwork/develop-webapp:latest image: ocelotsocialnetwork/webapp:latest
imagePullPolicy: Always imagePullPolicy: Always
name: web name: web
ports: ports:

View File

@ -1,17 +0,0 @@
version: "3.4"
services:
webapp:
environment:
- "CI=${CI}"
image: ocelotsocialnetwork/develop-webapp:build-and-test
build:
context: webapp
target: build-and-test
backend:
environment:
- "CI=${CI}"
image: ocelotsocialnetwork/develop-backend:build-and-test
build:
context: backend
target: build-and-test

View File

@ -1,57 +1,68 @@
version: "3.4" version: "3.4"
services: services:
########################################################
# WEBAPP ###############################################
########################################################
webapp: webapp:
image: ocelotsocialnetwork/develop-webapp:build-and-test image: ocelotsocialnetwork/webapp:development
build: build:
context: webapp target: development
target: build-and-test
environment: environment:
- NUXT_BUILD=/tmp/nuxt # avoid file permission issues when `rm -rf .nuxt/` - NODE_ENV="development"
- PUBLIC_REGISTRATION=true # - DEBUG=true
command: yarn run dev # - NUXT_BUILD=/tmp/nuxt # avoid file permission issues when `rm -rf .nuxt/`
volumes: volumes:
- ./webapp:/develop-webapp # This makes sure the docker container has its own node modules.
- webapp_node_modules:/develop-webapp/node_modules # Therefore it is possible to have a different node version on the host machine
- webapp_node_modules:/app/node_modules
# bind the local folder to the docker to allow live reload
- ./webapp:/app
########################################################
# BACKEND ##############################################
########################################################
backend: backend:
image: ocelotsocialnetwork/develop-backend:build-and-test image: ocelotsocialnetwork/backend:development
build: build:
context: backend target: development
target: build-and-test
command: yarn run dev
environment: environment:
- SMTP_HOST=mailserver - NODE_ENV="development"
- SMTP_PORT=25 - DEBUG=true
- SMTP_IGNORE_TLS=true
- "DEBUG=${DEBUG}"
- PUBLIC_REGISTRATION=false
volumes: volumes:
- ./backend:/develop-backend # This makes sure the docker container has its own node modules.
- backend_node_modules:/develop-backend/node_modules # Therefore it is possible to have a different node version on the host machine
- uploads:/develop-backend/public/uploads - backend_node_modules:/app/node_modules
# bind the local folder to the docker to allow live reload
- ./backend:/app
########################################################
# NEO4J ################################################
########################################################
neo4j: neo4j:
volumes: image: ocelotsocialnetwork/neo4j:development
- neo4j_data:/data
maintenance:
image: ocelotsocialnetwork/develop-maintenance:latest
build:
context: webapp
dockerfile: Dockerfile.maintenance
networks:
- hc-network
ports: ports:
- 3503:80 # Also expose the neo4j query browser
- 7474:7474
networks:
# So we can access the neo4j query browser from our host machine
- external-net
########################################################
# MAINTENANCE ##########################################
########################################################
maintenance:
image: ocelotsocialnetwork/maintenance:development
########################################################
# MAILSERVER TO FAKE SMTP ##############################
########################################################
mailserver: mailserver:
image: djfarrelly/maildev image: djfarrelly/maildev
ports: ports:
- 1080:80 - 1080:80
networks: networks:
- hc-network - external-net
networks:
hc-network:
volumes: volumes:
webapp_node_modules: webapp_node_modules:
backend_node_modules: backend_node_modules:
neo4j_data:
uploads:

View File

@ -1,20 +0,0 @@
version: "3.4"
services:
webapp:
build:
context: webapp
target: production
args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}"
backend:
build:
context: backend
target: production
args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}"
neo4j:
build:
context: neo4j
args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}"

View File

@ -1,75 +1,117 @@
# This file defines the production settings. It is overwritten by docker-compose.override.yml,
# which defines the development settings. The override.yml is loaded by default. Therefore it
# is required to explicitly define if you want an production build:
# > docker-compose -f docker-compose.yml up
version: "3.4" version: "3.4"
services: services:
########################################################
# WEBAPP ###############################################
########################################################
webapp: webapp:
image: ocelotsocialnetwork/develop-webapp:latest image: ocelotsocialnetwork/webapp:latest
build: build:
context: webapp context: ./webapp
target: production target: production
args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}"
ports:
- 3000:3000
- 3002:3002
networks: networks:
- hc-network - external-net
depends_on: depends_on:
- backend - backend
volumes: ports:
- ./webapp:/develop-webapp - 3000:3000
- webapp_node_modules:/develop-webapp/node_modules # Storybook: Todo externalize, its not working anyways
# - 3002:3002
environment: environment:
- HOST=0.0.0.0 # Envs used in Dockerfile
# - DOCKER_WORKDIR="/app"
# - PORT="3000"
- BUILD_DATE
- BUILD_VERSION
- BUILD_COMMIT
- NODE_ENV="development"
# Application only envs
- HOST=0.0.0.0 # This is nuxt specific, alternative value is HOST=webapp
- GRAPHQL_URI=http://backend:4000 - GRAPHQL_URI=http://backend:4000
- MAPBOX_TOKEN="pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g" env_file:
- ./webapp/.env
########################################################
# BACKEND ##############################################
########################################################
backend: backend:
image: ocelotsocialnetwork/develop-backend:latest image: ocelotsocialnetwork/backend:latest
build: build:
context: backend context: ./backend
target: production target: production
args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}"
networks: networks:
- hc-network - external-net
- internal-net
depends_on: depends_on:
- neo4j - neo4j
ports: ports:
- 4000:4000 - 4000:4000
volumes: volumes:
- ./backend:/develop-backend - backend_uploads:/app/public/uploads
- backend_node_modules:/develop-backend/node_modules
- uploads:/develop-backend/public/uploads
environment: environment:
# Envs used in Dockerfile
# - DOCKER_WORKDIR="/app"
# - PORT="4000"
- BUILD_DATE
- BUILD_VERSION
- BUILD_COMMIT
- NODE_ENV="development"
# Application only envs
- DEBUG=false
- NEO4J_URI=bolt://neo4j:7687 - NEO4J_URI=bolt://neo4j:7687
- GRAPHQL_URI=http://backend:4000 - GRAPHQL_URI=http://backend:4000
- CLIENT_URI=http://localhost:3000 - CLIENT_URI=http://webapp:3000
- JWT_SECRET=b/&&7b78BF&fv/Vd env_file:
- MAPBOX_TOKEN=pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g - ./backend/.env
- PRIVATE_KEY_PASSPHRASE=a7dsf78sadg87ad87sfagsadg78
- "DEBUG=${DEBUG}" ########################################################
- EMAIL_DEFAULT_SENDER=devops@ocelot.social # NEO4J ################################################
########################################################
neo4j: neo4j:
image: ocelotsocialnetwork/develop-neo4j:latest image: ocelotsocialnetwork/neo4j:latest
build: build:
context: neo4j context: ./neo4j
args: # community edition 👆🏼, because we have no enterprise licence 👇🏼 at the moment
- "BUILD_COMMIT=${TRAVIS_COMMIT}" target: community
networks: networks:
- hc-network - internal-net
environment:
- NEO4J_AUTH=none
- NEO4J_dbms_security_procedures_unrestricted=algo.*,apoc.*
# decomment following line for Neo4j Enterprice version instead of Community version
# - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
ports: ports:
- 7687:7687 - 7687:7687
- 7474:7474
volumes: volumes:
- neo4j_data:/data - neo4j_data:/data
environment:
# TODO: This sounds scary for a production environment
- NEO4J_AUTH=none
- NEO4J_dbms_security_procedures_unrestricted=algo.*,apoc.*
# Uncomment following line for Neo4j Enterprise version instead of Community version
# TODO: clarify if that is the only thing needed to unlock the Enterprise version
# - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
# TODO: Remove the playground from production
########################################################
# MAINTENANCE ##########################################
########################################################
maintenance:
image: ocelotsocialnetwork/maintenance:latest
build:
# TODO: Separate from webapp, this must be independent
context: ./webapp
dockerfile: Dockerfile.maintenance
networks:
- external-net
ports:
- 5000:80
networks: networks:
hc-network: external-net:
internal-net:
internal: true
volumes: volumes:
webapp_node_modules: backend_uploads:
backend_node_modules:
neo4j_data: neo4j_data:
uploads:

View File

@ -1,82 +0,0 @@
# Installation
The repository can be found on GitHub. [https://github.com/Ocelot-Social-Community/Ocelot-Social](https://github.com/Ocelot-Social-Community/Ocelot-Social)
We give write permissions to every developer who asks for it. Just text us on
[Discord](https://discord.gg/6ub73U3).
## Clone the Repository
Clone the repository, this will create a new folder called `Human-Connection`:
{% tabs %}
{% tab title="HTTPS" %}
```bash
$ git clone https://github.com/Ocelot-Social-Community/Ocelot-Social.git
```
{% endtab %}
{% tab title="SSH" %}
```bash
$ git clone git@github.com:Human-Connection/Human-Connection.git
```
{% endtab %}
{% endtabs %}
Change into the new folder.
```bash
$ cd Human-Connection
```
## Directory Layout
There are four important directories:
* [Backend](./backend) runs on the server and is a middleware between database and frontend
* [Frontend](./webapp) is a server-side-rendered and client-side-rendered web frontend
* [Deployment](./deployment) configuration for kubernetes
* [Cypress](./cypress) contains end-to-end tests and executable feature specifications
In order to setup the application and start to develop features you have to
setup **frontend** and **backend**.
There are two approaches:
1. Local installation, which means you have to take care of dependencies yourself
2. **Or** Install everything through docker which takes care of dependencies for you
## Docker Installation
Docker is a software development container tool that combines software and its dependencies into one standardized unit that contains everything needed to run it. This helps us to avoid problems with dependencies and makes installation easier.
### General Installation of Docker
There are [sevaral ways to install Docker CE](https://docs.docker.com/install/) on your computer or server.
{% tabs %}
{% tab title="Docker Desktop macOS" %}
Follow these instructions to [install Docker Desktop on macOS](https://docs.docker.com/docker-for-mac/install/).
{% endtab %}
{% tab title="Docker Desktop Windows" %}
Follow these instructions to [install Docker Desktop on Windows](https://docs.docker.com/docker-for-windows/install/).
{% endtab %}
{% tab title="Docker CE" %}
Follow these instructions to [install Docker CE](https://docs.docker.com/install/).
This is a great option for Linux users.
{% endtab %}
{% endtabs %}
Check the correct Docker installation by checking the version before proceeding. E.g. we have the following versions:
```bash
$ docker --version
Docker version 18.09.2
$ docker-compose --version
docker-compose version 1.23.2
```

View File

@ -1,10 +1,43 @@
FROM neo4j:3.5.14 ##################################################################################
LABEL Description="Neo4J database of the Social Network ocelot.social with preinstalled database constraints and indices" Vendor="ocelot.social Community" Version="0.0.1" Maintainer="ocelot.social Community (devops@ocelot.social)" # COMMUNITY ######################################################################
# community edition 👆🏼, because we have no enterprise licence 👇🏼 at the moment ##################################################################################
# FROM neo4j:3.5.14-enterprise FROM neo4j:3.5.14 as community
ARG BUILD_COMMIT # ENVs (available in production aswell, can be overwritten by commandline or env file)
ENV BUILD_COMMIT=$BUILD_COMMIT ## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0
ENV BUILD_DATE="1970-01-01T00:00:00.00Z"
## We cannot do $(yarn run version) here so we default to 0.0.0
## TODO: Missing Build number - do that once we have a CI which actually generates it
ENV BUILD_VERSION="0.0.0"
## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000
ENV BUILD_COMMIT="0000000"
# Labels
LABEL org.label-schema.build-date="${BUILD_DATE}"
LABEL org.label-schema.name="ocelot.social:backend"
LABEL org.label-schema.description="Neo4J database of the Social Network Software ocelot.social with preinstalled database constraints and indices"
LABEL org.label-schema.usage="https://github.com/Ocelot-Social-Community/Ocelot-Social/blob/master/README.md"
LABEL org.label-schema.url="https://ocelot.social"
LABEL org.label-schema.vcs-url="https://github.com/Ocelot-Social-Community/Ocelot-Social/tree/master/backend"
LABEL org.label-schema.vcs-ref="${BUILD_COMMIT}"
LABEL org.label-schema.vendor="ocelot.social Community"
LABEL org.label-schema.version="${BUILD_VERSION}"
LABEL org.label-schema.schema-version="1.0"
LABEL maintainer="devops@ocelot.social"
# Install Additional Software
## install: wget, htop (TODO: why do we need htop?)
RUN apt-get update && apt-get -y install wget htop RUN apt-get update && apt-get -y install wget htop
## install: apoc plugin for neo4j
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.4/apoc-3.5.0.4-all.jar -P plugins/
##################################################################################
# ENTERPRISE #####################################################################
##################################################################################
FROM neo4j:3.5.14-enterprise as enterprise
# Install Additional Software
## install: wget, htop (TODO: why do we need htop?)
RUN apt-get update && apt-get -y install wget htop
## install: apoc plugin for neo4j
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.4/apoc-3.5.0.4-all.jar -P plugins/ RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.4/apoc-3.5.0.4-all.jar -P plugins/

View File

@ -2,5 +2,5 @@
sed -i "s/<COMMIT>/${TRAVIS_COMMIT}/g" $TRAVIS_BUILD_DIR/scripts/patches/patch-deployment.yaml sed -i "s/<COMMIT>/${TRAVIS_COMMIT}/g" $TRAVIS_BUILD_DIR/scripts/patches/patch-deployment.yaml
sed -i "s/<COMMIT>/${TRAVIS_COMMIT}/g" $TRAVIS_BUILD_DIR/scripts/patches/patch-configmap.yaml sed -i "s/<COMMIT>/${TRAVIS_COMMIT}/g" $TRAVIS_BUILD_DIR/scripts/patches/patch-configmap.yaml
kubectl -n ocelot-social patch configmap develop-configmap -p "$(cat $TRAVIS_BUILD_DIR/scripts/patches/patch-configmap.yaml)" kubectl -n ocelot-social patch configmap develop-configmap -p "$(cat $TRAVIS_BUILD_DIR/scripts/patches/patch-configmap.yaml)"
kubectl -n ocelot-social patch deployment develop-backend -p "$(cat $TRAVIS_BUILD_DIR/scripts/patches/patch-deployment.yaml)" kubectl -n ocelot-social patch deployment backend -p "$(cat $TRAVIS_BUILD_DIR/scripts/patches/patch-deployment.yaml)"
kubectl -n ocelot-social patch deployment develop-webapp -p "$(cat $TRAVIS_BUILD_DIR/scripts/patches/patch-deployment.yaml)" kubectl -n ocelot-social patch deployment webapp -p "$(cat $TRAVIS_BUILD_DIR/scripts/patches/patch-deployment.yaml)"

View File

@ -4,14 +4,14 @@ ROOT_DIR=$(dirname "$0")/..
VERSION=$(jq -r '.version' $ROOT_DIR/package.json) VERSION=$(jq -r '.version' $ROOT_DIR/package.json)
IFS='.' read -r major minor patch <<< $VERSION IFS='.' read -r major minor patch <<< $VERSION
apps=(develop-webapp develop-backend develop-neo4j develop-maintenance) apps=(webapp backend neo4j maintenance)
tags=($major $major.$minor $major.$minor.$patch) tags=($major $major.$minor $major.$minor.$patch)
# These three docker images have already been built by now: # These three docker images have already been built by now:
# docker build --build-arg BUILD_COMMIT=$BUILD_COMMIT --target production -t ocelotsocialnetwork/develop-backend:latest $ROOT_DIR/backend # docker build --build-arg BUILD_COMMIT=$BUILD_COMMIT --target production -t ocelotsocialnetwork/backend:latest $ROOT_DIR/backend
# docker build --build-arg BUILD_COMMIT=$BUILD_COMMIT --target production -t ocelotsocialnetwork/develop-webapp:latest $ROOT_DIR/webapp # docker build --build-arg BUILD_COMMIT=$BUILD_COMMIT --target production -t ocelotsocialnetwork/webapp:latest $ROOT_DIR/webapp
# docker build --build-arg BUILD_COMMIT=$BUILD_COMMIT -t ocelotsocialnetwork/develop-neo4j:latest $ROOT_DIR/neo4j # docker build --build-arg BUILD_COMMIT=$BUILD_COMMIT -t ocelotsocialnetwork/neo4j:latest $ROOT_DIR/neo4j
docker build -t ocelotsocialnetwork/develop-maintenance:latest $ROOT_DIR/webapp/ -f $ROOT_DIR/webapp/Dockerfile.maintenance docker build -t ocelotsocialnetwork/maintenance:latest $ROOT_DIR/webapp/ -f $ROOT_DIR/webapp/Dockerfile.maintenance
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

View File

@ -1,32 +1,89 @@
##################################################################################
# BASE ###########################################################################
##################################################################################
FROM node:12.19.0-alpine3.10 as base FROM node:12.19.0-alpine3.10 as base
LABEL Description="Web Frontend of the Social Network ocelot.social" Vendor="ocelot.social Community" Version="0.0.1" Maintainer="ocelot.social Community (devops@ocelot.social)"
EXPOSE 3000 # ENVs (available in production aswell, can be overwritten by commandline or env file)
CMD ["yarn", "run", "start"] ## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame
ENV DOCKER_WORKDIR="/app"
## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0
ENV BUILD_DATE="1970-01-01T00:00:00.00Z"
## We cannot do $(yarn run version) here so we default to 0.0.0
## TODO: Missing Build number - do that once we have a CI which actually generates it
ENV BUILD_VERSION="0.0.0"
## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000
ENV BUILD_COMMIT="0000000"
## SET NODE_ENV
ENV NODE_ENV="production"
## App relevant Envs
ENV PORT="3000"
# Expose the app port # Labels
ARG BUILD_COMMIT LABEL org.label-schema.build-date="${BUILD_DATE}"
ENV BUILD_COMMIT=$BUILD_COMMIT LABEL org.label-schema.name="ocelot.social:backend"
ARG WORKDIR=/develop-webapp LABEL org.label-schema.description="Web Frontend of the Social Network Software ocelot.social"
RUN mkdir -p $WORKDIR LABEL org.label-schema.usage="https://github.com/Ocelot-Social-Community/Ocelot-Social/blob/master/README.md"
WORKDIR $WORKDIR LABEL org.label-schema.url="https://ocelot.social"
LABEL org.label-schema.vcs-url="https://github.com/Ocelot-Social-Community/Ocelot-Social/tree/master/backend"
LABEL org.label-schema.vcs-ref="${BUILD_COMMIT}"
LABEL org.label-schema.vendor="ocelot.social Community"
LABEL org.label-schema.version="${BUILD_VERSION}"
LABEL org.label-schema.schema-version="1.0"
LABEL maintainer="devops@ocelot.social"
# See: https://github.com/nodejs/docker-node/pull/367#issuecomment-430807898 # Install Additional Software
## install: git
RUN apk --no-cache add git RUN apk --no-cache add git
COPY package.json yarn.lock ./ # Settings
COPY .env.template .env ## Expose Container Port
EXPOSE ${PORT}
## Workdir
RUN mkdir -p ${DOCKER_WORKDIR}
WORKDIR ${DOCKER_WORKDIR}
FROM base as build-and-test ##################################################################################
RUN yarn install --production=false --frozen-lockfile --non-interactive # DEVELOPMENT (Connected to the local environment, to reload on demand) ##########
##################################################################################
FROM base as development
# We don't need to copy or build anything since we gonna bind to the
# local filesystem which will need a rebuild anyway
# Run command
# (for development we need to execute yarn install since the
# node_modules are on another volume and need updating)
CMD /bin/sh -c "yarn install && yarn run dev"
##################################################################################
# BUILD (Does contain all files and is therefore bloated) ########################
##################################################################################
FROM base as build
# Copy everything
COPY . . COPY . .
RUN NODE_ENV=production yarn run build # yarn install
RUN yarn install --production=false --frozen-lockfile --non-interactive
# yarn build
RUN yarn run build
##################################################################################
# PRODUCTION (Does contain only "binary"- and static-files to reduce image size) #
##################################################################################
FROM base as production FROM base as production
RUN yarn install --production=true --frozen-lockfile --non-interactive --no-cache
COPY --from=build-and-test ./develop-webapp/.nuxt ./.nuxt # Copy "binary"-files from build image
COPY --from=build-and-test ./develop-webapp/constants ./constants COPY --from=build ${DOCKER_WORKDIR}/.nuxt ./.nuxt
COPY --from=build-and-test ./develop-webapp/static ./static COPY --from=build ${DOCKER_WORKDIR}/node_modules ./node_modules
COPY nuxt.config.js . COPY --from=build ${DOCKER_WORKDIR}/nuxt.config.js ./nuxt.config.js
COPY locales locales # Copy static files
# TODO - this should be one Folder containign all stuff needed to be copied
COPY --from=build ${DOCKER_WORKDIR}/constants ./constants
COPY --from=build ${DOCKER_WORKDIR}/static ./static
COPY --from=build ${DOCKER_WORKDIR}/locales ./locales
# Copy package.json for script definitions (lock file should not be needed)
COPY --from=build ${DOCKER_WORKDIR}/package.json ./package.json
# Run command
CMD /bin/sh -c "yarn run start"

View File

@ -36,7 +36,7 @@ $ docker-compose up
```` ````
And the maintenance mode page or service will be started as well in an own container. And the maintenance mode page or service will be started as well in an own container.
In the browser you can reach it under `http://localhost:3503/`. In the browser you can reach it under `http://localhost:5000/`.
{% endtab %} {% endtab %}
{% tab title="On The Server" %} {% tab title="On The Server" %}

View File

@ -17,7 +17,7 @@
"lint": "eslint --ext .js,.vue .", "lint": "eslint --ext .js,.vue .",
"locales": "../scripts/translations/missing-keys.sh && ../scripts/translations/sort.sh", "locales": "../scripts/translations/missing-keys.sh && ../scripts/translations/sort.sh",
"precommit": "yarn lint", "precommit": "yarn lint",
"test": "jest", "test": "cross-env NODE_ENV=test jest",
"test:unit:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --no-cache --runInBand" "test:unit:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --no-cache --runInBand"
}, },
"jest": { "jest": {
@ -33,7 +33,7 @@
], ],
"transform": { "transform": {
".*\\.(vue)$": "vue-jest", ".*\\.(vue)$": "vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest" "^.+\\.js$": "babel-jest"
}, },
"moduleFileExtensions": [ "moduleFileExtensions": [
"js", "js",