Skip to content

Commit

Permalink
feat: add docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
dword-design committed Feb 26, 2021
1 parent d88f5c6 commit 166db18
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
},
"dependencies": {
"@dword-design/base-config-nuxt": "^2.8.0",
"@dword-design/functions": "^1.2.0",
"@semantic-release/exec": "^5.0.0",
"ceiling": "^2.2.4",
"depcheck-package-name": "^1.0.0",
"execa": "^5.0.0",
"fs-extra": "^9.0.1",
"hosted-git-info": "^3.0.8",
"load-pkg": "^4.0.0",
"output-files": "^1.1.20",
"parse-git-config": "^3.0.0",
"parse-pkg-name": "^2.0.0",
"pm2": "^4.4.0"
"pm2": "^4.4.0",
"yaml": "^1.10.0"
},
"devDependencies": {
"@dword-design/base": "^7.0.0",
Expand Down
19 changes: 19 additions & 0 deletions src/docker-compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
services: {
proxy: {
depends_on: ['web'],
image: 'nginx:1',
ports: ['80:80'],
volumes: ['./nginx:/etc/nginx/conf.d'],
},
web: {
command: 'bash -c "yarn --frozen-lockfile && yarn dev"',
environment: ['HOST=0.0.0.0'],
image: 'node:12',
ports: ['3000:3000'],
volumes: ['.:/app', '/app/node_modules'],
working_dir: '/app',
},
},
version: '3',
}
25 changes: 21 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
import nuxtConfig from '@dword-design/base-config-nuxt'
import packageName from 'depcheck-package-name'
import execa from 'execa'
import { outputFile } from 'fs-extra'
import loadPkg from 'load-pkg'
import outputFiles from 'output-files'
import yaml from 'yaml'

import dockerCompose from './docker-compose'
import ecosystem from './ecosystem'
import nginxConfig from './nginx-config'

const packageConfig = loadPkg.sync()

export default {
...nuxtConfig,
allowedMatches: [...nuxtConfig.allowedMatches, 'ecosystem.json'],
editorIgnore: [...nuxtConfig.editorIgnore, 'ecosystem.json'],
allowedMatches: [
...nuxtConfig.allowedMatches,
'docker-compose.yml',
'ecosystem.json',
'nginx',
],
editorIgnore: [
...nuxtConfig.editorIgnore,
'docker-compose.yml',
'ecosystem.json',
'nginx',
],
gitignore: [...nuxtConfig.gitignore, '/.ceilingrc.json'],
npmPublish: false,
packageConfig: {
main: 'dist/index.js',
},
prepare: async () => {
await nuxtConfig.prepare()
return outputFile('ecosystem.json', JSON.stringify(ecosystem, undefined, 2))
return outputFiles({
'docker-compose.yml': yaml.stringify(dockerCompose),
'ecosystem.json': JSON.stringify(ecosystem, undefined, 2),
'nginx/default.config': JSON.stringify(nginxConfig, undefined, 2),
})
},
useJobMatrix: false,
...(!packageConfig.private && {
Expand Down
24 changes: 24 additions & 0 deletions src/nginx-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { endent } from '@dword-design/functions'
import loadPkg from 'load-pkg'
import parsePkgName from 'parse-pkg-name'

const packageConfig = loadPkg.sync()
const packageName = parsePkgName(packageConfig.name).name

export default endent`
upstream web {
server web:3000;
}
server {
listen 80;
server_name ${packageName}.test;
location / {
proxy_pass http://web;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
`
11 changes: 10 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,15 @@
lodash "^4.17.15"
tinycolor2 "^1.4.1"

"@dword-design/functions@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@dword-design/functions/-/functions-1.2.0.tgz#fa4ed4643a4f801f0f984d09bcef32c3b71afffb"
integrity sha512-TE6zdexGjlj6t5CaVtfh28rTSdQOOxhmRzkj0++cc7G4xe3dJ3xVvT9k6O0ECrPnHOMypkoCcXOo5SNFmBUQRw==
dependencies:
endent dword-design/endent#fork
lodash "^4.17.15"
tinycolor2 "^1.4.1"

"@dword-design/functions@^2.2.2", "@dword-design/functions@^2.2.4", "@dword-design/functions@^2.6.3", "@dword-design/functions@^2.7.0", "@dword-design/functions@^2.7.2":
version "2.7.2"
resolved "https://registry.yarnpkg.com/@dword-design/functions/-/functions-2.7.2.tgz#08ef65bf7fea7cfb1e4252ce4536df46b866cf0e"
Expand Down Expand Up @@ -10541,7 +10550,7 @@ osenv@^0.1.4, osenv@^0.1.5:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

output-files@^1.1.10, output-files@^1.1.7:
output-files@^1.1.10, output-files@^1.1.20, output-files@^1.1.7:
version "1.1.20"
resolved "https://registry.yarnpkg.com/output-files/-/output-files-1.1.20.tgz#78936102b245a564ac3ed6e18afe4a5612768ad4"
integrity sha512-l6u9rWngf4WX80K9UOBunWLJtWyJKcSJ20dDSkr95Fiys2FslrQYeU4ensRcy1HHbM7mBwnnxzzxZoAIv6nyeA==
Expand Down

0 comments on commit 166db18

Please sign in to comment.