Sign inSign up

alehungate/ossn

By alehungate

•Updated almost 6 years ago

Open Source Social Network in Docker - https://www.opensource-socialnetwork.org/

Image
0

413

alehungate/ossn repository overview

⁠Open Source Social Network in Docker

⁠Where?

⁠What?

The packaging of this app has been designed to make it easy to run OSSN under Kubernetes, although there is no reason you shouldn't run it under Swarm or just as a plain docker container.

⁠Volume Mount Points

  • /var/www/localhost - This contains the website (in ./htdocs) and the user data (in ./data) both of which are created automatically on first start.

⁠Database

  • OSSN requires a MySQL or MariaDB database. The startup script will create the database and tables on first start.

⁠Environment Variables

  • SMTP_SERVER - Default smtp - The hostname of the smtp server to use (See below for help on hostnames in Kubernetes)
  • SITE_SCHEME - Default http - The scheme over which the site will be accessed
  • SITE_HOSTNAME - Default localhost - The hostname that the site is accessed on
  • SITE_PATH - Default / - The / terminated path that the site is accessible at
  • SITE_NAME - Default Default Site Name - The display name of the site
  • OWNER_EMAIL - Default [email protected] - The email address for problems etc
  • SITE_KEY - Default complex-site-key-should-go-here - A key with which OSSN can encrypt certain data etc
  • DB_HOST - Default mysql - The hostname of the MySQL/MariaDB server (See below for help on hostnames in Kubernetes)
  • DB_PORT - Default 3306 - The port that MySQL/MariaDB is listening on
  • DB_USER - Required - The user to log into the database with
  • DB_PASS - Required - The password to log into the database with
  • DB_NAME - Default ossn - The database to use in MySQL/MariaDB
  • DB_ROOT_USER - Optional - An administrative user to create the database with. If this is not provided then you must create the database and grant the user access before starting the container
  • DB_ROOT_PASS - Optional - The password for the administrative user
  • ADMIN_USER - Required - Initial admin user name
  • ADMIN_PASS - Required - Initial admin user password

⁠Hostnames in Kubernetes

If you are not familiar with Kubernetes it can be daunting to work out how everything stitches together, so I've put a few of pointers here to try to help out.

Firstly, in Kubernetes, docker containers run as Pods, however you don't talk directly to a Pod but instead to a Service the points to a Pod. For example:

Namespace: mynamespace

Name: mypod-xyz-abc123     Service: myservice
+---------+                +---------------+
| Pod     | <------------- | Service       |
| Port 80 |                | Port 80 -> 80 |
+---------+                +---------------+

This could be defined using the following YAML:

---
kind: Pod
apiVersion: v1
metadata:
  name: mypod-xyz-abc123
  namespace: mynamespace
  labels:
    app: mypod
spec:
  containers:
    - name: mypod
      image: httpd
      ports:
        - name: http
          containerPort: 80
          protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: myservice
  namespace: mynamespace
spec:
  ports:
    - port: 80
  selector:
    app: mypod
---

To access this host. within a default cluster (where the cluster top level domain is cluster.local) you could use the following FQDN URL:

http://myservice.mynamespace.svc.cluster.local

or, as every namespace gets the cluster as part of the DNS search path:

http://myservice.mynamespace.svc

As you should be able to see, the service is listening (Cluster wide!) on port 80. It is registered in the cluster DNS (kubedns or coredns) as myservice.mynamespace.svc however Pods within the namespace mynamespace include mynamespace.svc in their DNS search path, so within the same namespace services can be referenced using localname (myservice) alone, so for another Pod running in namespace mynamespace can just say:

http://myservice

So, for example, in one of my clusters I run a service smtp (listening on port 25) in the namespace exim, so all other pods in the cluster can send email over SMTP via the hostname smtp.exim.svc.

⁠Example deployment manifest for Kubernetes

---
apiVersion: v1
kind: Namespace
metadata:
  name: ossn
---
# This password is `password` and should be changed to something FAR more secure
apiVersion: v1
data:
  password: cGFzc3dvcmQ=
kind: Secret
metadata:
  name: mysql-root-pass
  namespace: ossn
---
# This password is `password` and should be changed to something FAR more secure
apiVersion: v1
data:
  password: cGFzc3dvcmQ=
kind: Secret
metadata:
  name: mysql-ossn-pass
  namespace: ossn
---
# This site-key is `password` and should be changed to something FAR more secure
apiVersion: v1
data:
  site-key: cGFzc3dvcmQ=
kind: Secret
metadata:
  name: site-key
  namespace: ossn
---
# This secret is for the initial admin user
apiVersion: v1
kind: Secret
stringData:
  user: admin
  password: admin
metadata:
  name: admin-user
  namespace: ossn
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: ossn
  labels:
    app: mysql
spec:
  ports:
    - port: 3306
  selector:
    app: mysql
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-data
  namespace: ossn
  labels:
    app: mysql
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: mysql
  namespace: ossn
  labels:
    app: mysql
spec:
  replicas: 1
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-root-pass
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-data
---
apiVersion: v1
kind: Service
metadata:
  name: ossn
  namespace: ossn
  labels:
    app: ossn
spec:
  ports:
    - port: 80
  selector:
    app: ossn
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ossn-data
  namespace: ossn
  labels:
    app: ossn
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: ossn
  namespace: ossn
  labels:
    app: ossn
spec:
  replicas: 1
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: ossn
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: ossn
    spec:
      containers:
      - image: registry.example.com/ossn:latest
        name: ossn
        env:
        - name: SMTP_SERVER
          value: "smtp.exim.svc"
        - name: SITE_SCHEME
          value: "https"
        - name: SITE_HOSTNAME
          value: "ossn.example.com"
        - name: SITE_NAME
          value: "OSSN Sample Site"
        - name: OWNER_EMAIL
          value: "[email protected]"
        - name: SITE_KEY
          valueFrom:
            secretKeyRef:
              name: site-key
              key: site-key
        - name: DB_HOST
          value: "mysql"
        - name: DB_USER
          value: "ossn"
        - name: DB_PASS
          valueFrom:
            secretKeyRef:
              name: mysql-ossn-pass
              key: password
        - name: DB_ROOT_USER
          value: "root"
        - name: DB_ROOT_PASS
          valueFrom:
            secretKeyRef:
              name: mysql-root-pass
              key: password
        - name: DB_NAME
          value: "ossn"
        - name: ADMIN_USER
          valueFrom:
            secretKeyRef:
              name: admin-user
              key: user
        - name: ADMIN_PASS
          valueFrom:
            secretKeyRef:
              name: admin-user
              key: password
        volumeMounts:
        - name: data
          mountPath: /var/www/localhost
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: ossn-data
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ossn
  namespace: ossn
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  tls:
   - hosts:
     - ossn.example.com
     secretName: ossn.example.com
  rules:
  - host: ossn.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: ossn
          servicePort: 80

Tag summary

Content type

Image

Digest

Size

28.3 MB

Last updated

almost 6 years ago

docker pull alehungate/ossn