Skip to content

Instantly share code, notes, and snippets.

@R45H
Last active July 1, 2020 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R45H/74e4bdde11c75d60e098a1984106fd73 to your computer and use it in GitHub Desktop.
Save R45H/74e4bdde11c75d60e098a1984106fd73 to your computer and use it in GitHub Desktop.
gitlab-ci
image: node:12.17-alpine
variables:
# TODO: Use $CI_COMMIT_REF_SLUG to create different images
STAGING_IMAGE: '$CI_REGISTRY_IMAGE/b2b:latest'
stages:
- prepare
- test_and_assets
- build
- deploy_to_staging
- deploy_to_preproduction
prepare:
stage: prepare
tags:
- b2b-runner
script:
- node -v
- yarn --version
- yarn install --frozen-lockfile --prefer-offline
artifacts:
paths:
- node_modules
expire_in: 25 mins
lint:
stage: test_and_assets
tags:
- b2b-runner
script:
- yarn run lint
dependencies:
- prepare
build_assets:
stage: test_and_assets
tags:
- b2b-runner
script:
- yarn build
dependencies:
- prepare
artifacts:
paths:
- dist
expire_in: 25 mins
build:
only:
- master
image: docker:latest
stage: build
tags:
- b2b-runner
before_script:
- 'echo "Staging image: ${STAGING_IMAGE}"'
- 'echo "Building image"'
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $STAGING_IMAGE .
- docker push $STAGING_IMAGE
deploy_to_staging:
image: docker:latest
stage: deploy_to_staging
tags:
- b2b-runner
before_script:
- 'echo "Staging image: ${STAGING_IMAGE}"'
- 'echo "Will be deployed to b2b.nodejs-staging.amazon"'
- which ssh || (apk add --no-cache openssh-client)
- echo "$SSH_PRIVATE_KEY_FOR_NODEJS_STAGING" > ./id_rsa
- chmod 600 ./id_rsa
script:
- ssh -o StrictHostKeychecking=no -i ./id_rsa ci@nodejs-staging.amazon "
docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} &&
docker stop b2b || true &&
docker rm b2b || true &&
docker pull ${STAGING_IMAGE} &&
docker run -d
--name b2b
--env VIRTUAL_HOST=b2b.nodejs-staging.amazon
--network helpdesk
${STAGING_IMAGE}"
after_script:
- docker rmi ${STAGING_IMAGE}
- rm ./id_rsa
dependencies:
- prepare
- build_assets
when: manual
only:
variables:
- $SSH_PRIVATE_KEY_FOR_NODEJS_STAGING
environment:
name: staging/b2b
url: http://b2b.nodejs-staging.amazon
deploy_to_preproduction:
image: docker:latest
stage: deploy_to_preproduction
tags:
- b2b-runner
before_script:
- 'echo "Staging image: ${STAGING_IMAGE}"'
- 'echo "Will be deployed to account.b2b.somesite.ru"'
- which ssh || (apk add --no-cache openssh-client)
- echo "$SSH_PRIVATE_KEY_FOR_PREPRODUCTION" > ./id_rsa
- chmod 600 ./id_rsa
script:
- ssh -o StrictHostKeychecking=no -i ./id_rsa ci@dev-b2b-docker.amazon "
docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} &&
docker rm -f web-b2b || true &&
docker pull ${STAGING_IMAGE} &&
docker run -d -p 4001:80
--name web-b2b
--env VIRTUAL_HOST=account.b2b.somesite.ru
${STAGING_IMAGE}"
after_script:
- docker rmi ${STAGING_IMAGE}
- rm ./id_rsa
dependencies:
- prepare
- build_assets
when: manual
only:
variables:
- $SSH_PRIVATE_KEY_FOR_NODEJS_STAGING
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const PRODUCTION = 'production'
const DEVELOPMENT = 'development'
const { NODE_ENV } = process.env
const IS_PROD = NODE_ENV === PRODUCTION
const plugins = [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../app/index.html'),
filename: 'index.html',
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
]
const entry = {
app: [path.resolve(__dirname, '../app/index.js')],
}
if (!IS_PROD) {
plugins.push(new webpack.HotModuleReplacementPlugin())
entry.app.unshift('webpack-hot-middleware/client?reload=true')
}
module.exports = {
mode: IS_PROD ? PRODUCTION : DEVELOPMENT,
entry,
devtool: IS_PROD ? false : 'source-map',
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: {
name: 'runtime',
},
},
plugins,
devServer: {
contentBase: path.resolve(__dirname, '../dist'),
hot: true,
},
output: {
filename: '[name].[hash].js',
path: path.resolve(__dirname, '../dist'),
publicPath: '/',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment