0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UbuntuにCodiMDをManual Deploymentするときのメモ

Last updated at Posted at 2025-10-04

CodiMDの導入にはこちらを参考にしましたが、書いてある通りにやってみても自分の環境ではエラーが出たため、自分がうまくいった工程をここにメモとして残しておきます。

環境

Ubuntu 24.04.3 LTS

導入手順

nodejsとnpmのインストール

sudo apt install vim git libssl-dev -y
cd ~
sudo apt install nodejs -y
sudo apt install npm -y
sudo npm install -g n
sudo n 10.19.0
#ここでnodeのバージョンが変わっていないことがあるのでPCを再起動する
sudo reboot
sudo npm install -g yarn
sudo yarn install
sudo npm install -g npm@6.9.0

PostgreSQLにDBを作成

sudo apt install postgresql -y
sudo -u postgres psql
create role hackmd with login password 'hackmdpass';
create database hackmd owner hackmd encoding 'UTF8';
\q

CodiMDを導入

cd ~
sudo mkdir work
cd work
# 最新の2.6.1だとエラーがでたので、2.5.4を選択
git clone https://github.com/hackmdio/codimd.git -b 2.5.4 --depth 1 
cd codimd
bin/setup
#ここでエラーが出ても npm audit fix しないことが重要!

config.jsonファイルを編集

sudo vim config.json
:warning: development 部分を編集する

{
    "test": {
        "db": {
            "dialect": "sqlite",
            "storage": ":memory:"
        },
        "linkifyHeaderStyle": "gfm"
    },
    "development": {
        "loglevel": "info",
        "hsts": {
            "enable": false
        },
        "db": {
    	    "username": "hackmd",
    	    "password": "hackmdpass",
    	    "database": "hackmd",
    	    "host": "localhost",
    	    "port": "5432",
            "dialect": "postgres"
        },
        "linkifyHeaderStyle": "gfm",
    	"defaultPermission": "freely",
    	"allowAnonymous": true,
    	"allowFreeURL": false,
    	"allowPDFExport": true,
    	"email": true,
    	"allowEmailRegister": true
    },
    "production": {
        "domain": "localhost",
        "loglevel": "info",
        "hsts": {
            "enable": true,
            "maxAgeSeconds": 31536000,
            "includeSubdomains": true,
            "preload": true
        },
        "csp": {
            "enable": true,
            "directives": {
            },
            "upgradeInsecureRequests": "auto",
            "addDefaults": true,
            "addDisqus": true,
            "addGoogleAnalytics": true
        },
        "db": {
            "username": "",
            "password": "",
            "database": "codimd",
            "host": "localhost",
            "port": "5432",
            "dialect": "postgres"
        },
        "facebook": {
            "clientID": "change this",
            "clientSecret": "change this"
        },
        "twitter": {
            "consumerKey": "change this",
            "consumerSecret": "change this"
        },
        "github": {
            "clientID": "change this",
            "clientSecret": "change this",
            "organizations": ["names of github organizations allowed, optional"],
            "scopes": ["defaults to 'read:user' scope for auth user"]
        },
        "gitlab": {
            "baseURL": "change this",
            "clientID": "change this",
            "clientSecret": "change this",
            "scope": "use 'read_user' scope for auth user only or remove this property if you need gitlab snippet import/export support (will result to be default scope 'api')",
            "version": "use 'v4' if gitlab version > 11, 'v3' otherwise. Default to 'v4'"
        },
        "mattermost": {
            "baseURL": "change this",
            "clientID": "change this",
            "clientSecret": "change this"
        },
        "dropbox": {
            "clientID": "change this",
            "clientSecret": "change this",
            "appKey": "change this"
        },
        "google": {
            "clientID": "change this",
            "clientSecret": "change this",
            "apiKey": "change this"
        },
        "ldap": {
            "url": "ldap://change_this",
            "bindDn": null,
            "bindCredentials": null,
            "searchBase": "change this",
            "searchFilter": "change this",
            "searchAttributes": ["change this"],
            "usernameField": "change this e.g. cn",
            "useridField": "change this e.g. uid",
            "tlsOptions": {
                "changeme": "See https://nodejs.org/api/tls.html#tls_tls_connect_options_callback"
            }
        },
        "saml": {
            "idpSsoUrl": "change: authentication endpoint of IdP",
            "idpCert": "change: certificate file path of IdP in PEM format",
            "issuer": "change or delete: identity of the service provider (default: serverurl)",
            "identifierFormat": "change or delete: name identifier format (default: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress')",
            "disableRequestedAuthnContext": "change or delete: true to allow any authentication method, false restricts to password authentication method (default: false)",
            "groupAttribute": "change or delete: attribute name for group list (ex: memberOf)",
            "requiredGroups": [ "change or delete: group names that allowed" ],
            "externalGroups": [ "change or delete: group names that not allowed" ],
            "attribute": {
               "id": "change or delete this: attribute map for `id` (default: NameID)",
               "username": "change or delete this: attribute map for `username` (default: NameID)",
               "email": "change or delete this: attribute map for `email` (default: NameID)"
            }
        },
        "imgur": {
            "clientID": "change this"
        },
        "minio": {
          "accessKey": "change this",
          "secretKey": "change this",
          "endPoint": "change this",
          "secure": true,
          "port": 9000
        },
        "s3": {
          "accessKeyId": "change this",
          "secretAccessKey": "change this",
          "region": "change this"
        },
        "s3bucket": "change this",
        "azure":
        {
          "connectionString": "change this",
          "container": "change this"
        },
        "plantuml":
        {
          "server": "https://www.plantuml.com/plantuml"
        },
        "linkifyHeaderStyle": "gfm"
    }
}

.sequelizercを編集

sudo vim .sequelizerc

const path = require('path')
const config = require('./lib/config')

module.exports = {
  config: path.resolve('config.js'),
  'migrations-path': path.resolve('lib', 'migrations'),
  'models-path': path.resolve('lib', 'models'),
  url: 'postgres://hackmd:hackmdpass@localhost:5432/hackmd'
}

CodiMDをビルド + 起動

node_modules/.bin/sequelize db:migrate
npm run build
NODE_ENV='development'
node app.js

CodiMDの起動を確認する

ブラウザで http://localhost:3000 にアクセスする
image.png

CodiMDをManual Deploymentするときのコツ

nodenpmCodiMDバージョンを細かく指定する ことが重要みたいです

  • node 10.19.0
  • npm 6.9.0
  • CodiMD 2.5.4
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?