diff --git a/packages/cna-template/template/_Dockerfile b/packages/cna-template/template/_Dockerfile new file mode 100644 index 000000000..3923d99eb --- /dev/null +++ b/packages/cna-template/template/_Dockerfile @@ -0,0 +1,25 @@ +# Dockerfile +FROM node:14-alpine + +# create destination directory +RUN mkdir -p /app +WORKDIR /app + +# update and install dependency +RUN apk update && apk upgrade +RUN apk add git + +# install packages +COPY package.json . +COPY yarn.lock . +RUN yarn install + +# copy project to directory +COPY . . +RUN yarn build + +EXPOSE 80 +ENV NUXT_PORT=80 +ENV HOST 0.0.0.0 + +CMD [ "yarn", "start" ] diff --git a/packages/cna-template/template/_docker-compose.yml b/packages/cna-template/template/_docker-compose.yml new file mode 100644 index 000000000..3b7711664 --- /dev/null +++ b/packages/cna-template/template/_docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.7' + +services: + app: + build: . + image: <%= name %>/<%= name %> + container_name: <%= name %> + restart: always diff --git a/packages/create-nuxt-app/lib/prompts.js b/packages/create-nuxt-app/lib/prompts.js index 4232455c4..d4bb7dfb9 100644 --- a/packages/create-nuxt-app/lib/prompts.js +++ b/packages/create-nuxt-app/lib/prompts.js @@ -112,5 +112,15 @@ module.exports = [ { name: 'Semantic Pull Requests', value: 'semantic-pull-requests' } ], default: [] + }, + { + name: 'devOps', + message: 'DevOps tools:', + type: 'list', + choices: [ + { name: 'None', value: 'none' }, + { name: 'Docker', value: 'docker' } + ], + default: 'none' } ] diff --git a/packages/create-nuxt-app/lib/saofile.js b/packages/create-nuxt-app/lib/saofile.js index c899c0dac..e8642ed1e 100644 --- a/packages/create-nuxt-app/lib/saofile.js +++ b/packages/create-nuxt-app/lib/saofile.js @@ -81,6 +81,8 @@ module.exports = { '_.eslintrc.js': 'linter.includes("eslint")', '_.prettierrc': 'linter.includes("prettier")', '_jsconfig.json': 'devTools.includes("jsconfig.json")', + _Dockerfile: 'devOps.includes("docker")', + '_docker-compose.yml': 'devOps.includes("docker")', 'tsconfig.json': 'language.includes("ts")', 'semantic.yml': 'devTools.includes("semantic-pull-requests")', '_stylelint.config.js': 'linter.includes("stylelint")' @@ -96,6 +98,8 @@ module.exports = { '_.prettierrc': '.prettierrc', '_.eslintrc.js': '.eslintrc.js', '_jsconfig.json': 'jsconfig.json', + _Dockerfile: 'Dockerfile', + '_docker-compose.yml': 'docker-compose.yml', '_stylelint.config.js': 'stylelint.config.js', 'semantic.yml': '.github/semantic.yml' } diff --git a/packages/create-nuxt-app/test/snapshots/index.test.js.md b/packages/create-nuxt-app/test/snapshots/index.test.js.md index 6792b3995..55f616b6a 100644 --- a/packages/create-nuxt-app/test/snapshots/index.test.js.md +++ b/packages/create-nuxt-app/test/snapshots/index.test.js.md @@ -4202,3 +4202,323 @@ Generated by [AVA](https://avajs.dev). }␊ }␊ ` + +## verify devOps: Dockerize project + +> Generated files + + [ + '.editorconfig', + '.gitignore', + 'Dockerfile', + 'README.md', + 'assets/README.md', + 'components/Logo.vue', + 'components/README.md', + 'docker-compose.yml', + 'layouts/README.md', + 'layouts/default.vue', + 'middleware/README.md', + 'nuxt.config.js', + 'package.json', + 'pages/README.md', + 'pages/index.vue', + 'plugins/README.md', + 'static/README.md', + 'static/favicon.ico', + 'store/README.md', + ] + +> package.json + + { + dependencies: { + nuxt: '^2.14.0', + }, + devDependencies: {}, + private: true, + scripts: { + build: 'nuxt build', + dev: 'nuxt', + generate: 'nuxt generate', + start: 'nuxt start', + }, + } + +## verify devOps: None + +> Generated files + + [ + '.editorconfig', + '.gitignore', + 'README.md', + 'assets/README.md', + 'components/Logo.vue', + 'components/README.md', + 'layouts/README.md', + 'layouts/default.vue', + 'middleware/README.md', + 'nuxt.config.js', + 'package.json', + 'pages/README.md', + 'pages/index.vue', + 'plugins/README.md', + 'static/README.md', + 'static/favicon.ico', + 'store/README.md', + ] + +> package.json + + { + dependencies: { + nuxt: '^2.14.0', + }, + devDependencies: {}, + private: true, + scripts: { + build: 'nuxt build', + dev: 'nuxt', + generate: 'nuxt generate', + start: 'nuxt start', + }, + } + +## verify devOps: Dockerize project + +> Generated nuxt.config.js + + `␊ + export default {␊ + /*␊ + ** Nuxt rendering mode␊ + ** See https://nuxtjs.org/api/configuration-mode␊ + */␊ + mode: 'universal',␊ + /*␊ + ** Nuxt target␊ + ** See https://nuxtjs.org/api/configuration-target␊ + */␊ + target: 'server',␊ + /*␊ + ** Headers of the page␊ + ** See https://nuxtjs.org/api/configuration-head␊ + */␊ + head: {␊ + title: process.env.npm_package_name || '',␊ + meta: [␊ + { charset: 'utf-8' },␊ + { name: 'viewport', content: 'width=device-width, initial-scale=1' },␊ + { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊ + ],␊ + link: [␊ + { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊ + ]␊ + },␊ + /*␊ + ** Global CSS␊ + */␊ + css: [␊ + ],␊ + /*␊ + ** Plugins to load before mounting the App␊ + ** https://nuxtjs.org/guide/plugins␊ + */␊ + plugins: [␊ + ],␊ + /*␊ + ** Auto import components␊ + ** See https://nuxtjs.org/api/configuration-components␊ + */␊ + components: true,␊ + /*␊ + ** Nuxt.js dev-modules␊ + */␊ + buildModules: [␊ + ],␊ + /*␊ + ** Nuxt.js modules␊ + */␊ + modules: [␊ + ],␊ + /*␊ + ** Build configuration␊ + ** See https://nuxtjs.org/api/configuration-build/␊ + */␊ + build: {␊ + }␊ + }␊ + ` + +## verify devOps: None + +> Generated nuxt.config.js + + `␊ + export default {␊ + /*␊ + ** Nuxt rendering mode␊ + ** See https://nuxtjs.org/api/configuration-mode␊ + */␊ + mode: 'universal',␊ + /*␊ + ** Nuxt target␊ + ** See https://nuxtjs.org/api/configuration-target␊ + */␊ + target: 'server',␊ + /*␊ + ** Headers of the page␊ + ** See https://nuxtjs.org/api/configuration-head␊ + */␊ + head: {␊ + title: process.env.npm_package_name || '',␊ + meta: [␊ + { charset: 'utf-8' },␊ + { name: 'viewport', content: 'width=device-width, initial-scale=1' },␊ + { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊ + ],␊ + link: [␊ + { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊ + ]␊ + },␊ + /*␊ + ** Global CSS␊ + */␊ + css: [␊ + ],␊ + /*␊ + ** Plugins to load before mounting the App␊ + ** https://nuxtjs.org/guide/plugins␊ + */␊ + plugins: [␊ + ],␊ + /*␊ + ** Auto import components␊ + ** See https://nuxtjs.org/api/configuration-components␊ + */␊ + components: true,␊ + /*␊ + ** Nuxt.js dev-modules␊ + */␊ + buildModules: [␊ + ],␊ + /*␊ + ** Nuxt.js modules␊ + */␊ + modules: [␊ + ],␊ + /*␊ + ** Build configuration␊ + ** See https://nuxtjs.org/api/configuration-build/␊ + */␊ + build: {␊ + }␊ + }␊ + ` + +## verify devOps: Docker + +> Generated files + + [ + '.editorconfig', + '.gitignore', + 'Dockerfile', + 'README.md', + 'assets/README.md', + 'components/Logo.vue', + 'components/README.md', + 'docker-compose.yml', + 'layouts/README.md', + 'layouts/default.vue', + 'middleware/README.md', + 'nuxt.config.js', + 'package.json', + 'pages/README.md', + 'pages/index.vue', + 'plugins/README.md', + 'static/README.md', + 'static/favicon.ico', + 'store/README.md', + ] + +> package.json + + { + dependencies: { + nuxt: '^2.14.0', + }, + devDependencies: {}, + private: true, + scripts: { + build: 'nuxt build', + dev: 'nuxt', + generate: 'nuxt generate', + start: 'nuxt start', + }, + } + +> Generated nuxt.config.js + + `␊ + export default {␊ + /*␊ + ** Nuxt rendering mode␊ + ** See https://nuxtjs.org/api/configuration-mode␊ + */␊ + mode: 'universal',␊ + /*␊ + ** Nuxt target␊ + ** See https://nuxtjs.org/api/configuration-target␊ + */␊ + target: 'server',␊ + /*␊ + ** Headers of the page␊ + ** See https://nuxtjs.org/api/configuration-head␊ + */␊ + head: {␊ + title: process.env.npm_package_name || '',␊ + meta: [␊ + { charset: 'utf-8' },␊ + { name: 'viewport', content: 'width=device-width, initial-scale=1' },␊ + { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊ + ],␊ + link: [␊ + { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊ + ]␊ + },␊ + /*␊ + ** Global CSS␊ + */␊ + css: [␊ + ],␊ + /*␊ + ** Plugins to load before mounting the App␊ + ** https://nuxtjs.org/guide/plugins␊ + */␊ + plugins: [␊ + ],␊ + /*␊ + ** Auto import components␊ + ** See https://nuxtjs.org/api/configuration-components␊ + */␊ + components: true,␊ + /*␊ + ** Nuxt.js dev-modules␊ + */␊ + buildModules: [␊ + ],␊ + /*␊ + ** Nuxt.js modules␊ + */␊ + modules: [␊ + ],␊ + /*␊ + ** Build configuration␊ + ** See https://nuxtjs.org/api/configuration-build/␊ + */␊ + build: {␊ + }␊ + }␊ + ` diff --git a/packages/create-nuxt-app/test/snapshots/index.test.js.snap b/packages/create-nuxt-app/test/snapshots/index.test.js.snap index 3831b4189..25e601045 100644 Binary files a/packages/create-nuxt-app/test/snapshots/index.test.js.snap and b/packages/create-nuxt-app/test/snapshots/index.test.js.snap differ