# Deployment
# Nuxt-Bitbucket Deployment
This section is about how to setup a deployment in Bitbucket for a Nuxt server side rendered project.
The Pipeline looks like this at the moment.
image: node:10.15.3
pipelines:
default:
- step:
name: Build and test
caches:
- node
script:
- npm install
- npm run build
- echo "$(ls -la ./nuxt/)"
- ls -lah
artifacts: # defining the artifacts to be passed to each future step.
- .nuxt/*
- .nuxt/**
- .nuxt/dist/**
- .nuxt/dist/*
branches:
develop:
- step:
name: Build and test
caches:
- node
script:
- npm install
- npm run build
artifacts: # defining the artifacts to be passed to each future step.
- .nuxt/*
- .nuxt/**
- .nuxt/dist/**
- .nuxt/dist/*
- step:
name: Deploy Production
image: cabag/rsync
script:
- mkdir upload
- mv .nuxt/ static/ nuxt.config.js package.json i18n/ config/ upload
- echo "$(ls -la ./upload/)"
- rsync --no-perms -az "upload/" "${DEPLOY_USER}@${DEPLOY_HOST}:/home/${DEPLOY_USER}/apps/${PROJECT_NAME}/"
- ssh "${DEPLOY_USER}@${DEPLOY_HOST}" "cd /home/adufezuk/apps/${PROJECT_NAME} && npm install"
- >
if $(ssh "${DEPLOY_USER}@${DEPLOY_HOST}" "test -f ~/.services/supervisord/${PROJECT_NAME}/service.conf"); then
ssh "${DEPLOY_USER}@${DEPLOY_HOST}" "supervisorctl -c ~/.services/supervisord/hostpoint.conf restart ${PROJECT_NAME}";
else
ssh "${DEPLOY_USER}@${DEPLOY_HOST}" "hpservices supervisord add ${PROJECT_NAME}";
ssh "${DEPLOY_USER}@${DEPLOY_HOST}" bash -c "'
cat << EOF > ~/.services/supervisord/${PROJECT_NAME}/service.conf
[program:${PROJECT_NAME}]
command=npm run start
directory=%(ENV_HOME)s/apps/${PROJECT_NAME}/
stdout_logfile=%(ENV_HOME)s/.services/supervisord/${PROJECT_NAME}/log/default.log
stderr_logfile=%(ENV_HOME)s/.services/supervisord/${PROJECT_NAME}/log/default.err
EOF'";
ssh "${DEPLOY_USER}@${DEPLOY_HOST}" 'supervisorctl -c ~/.services/supervisord/hostpoint.conf update';
fi
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
- (Line 28-32) Important is the whole build is given to the next step as artifacts.
- (Line 37) Then we create a upload folder which is make it easier to just upload this folder with rsync.
- (Line 38) All files which are needed on the server to run the project are put into the upload folder.
- Inside the .nuxt/ folder is the whole build.
- Inside the static folder is are all static files which are not bundled from web pack.
- nuxt.config.js basic config of the nuxt project.
- package.json is needed because when don't have a standalone build(yet more on this below). so we need to run npm install on the server, otherwise we would need to copy the node_modules and that is not efficient.
- i18n I really don't know why this isn't in the build maybe someone can help. When we didn't deploy this folder we had a cannot find ./i18n module error and couldn't start the project.
- config is for the environment variables.
- (Line 40) Then we upload the upload folder with rsync.
- (Line 41) Next step is to login into the server and run the npm install on the server.
- (Line 43 - 53) Last step is to check if the project has already a supervisor config if not create one otherwise just restart the project. Supervisor is installed on the flex server from hostpoint.
# Bitbucket setup
- Go to settings.
Pipelines/ SSH Keysadd a new private and public key for the server and runknown_hostswith the server adress. (Login to the server and create withssh-keygen -N "" -m PEM -f projecta new key)Pipelines/ Repository Variablesadd all variables which are in the pipeline code. (Everything which start with a$and has curly braces)- Following Variables are used:
- DEPLOY_USER is the ssh user
- DEPLOY_HOST is the name for the ssh server
- PROJECT_NAME is the name used for the supervisor process
- Following Variables are used:
# Hostpoint setup(optional)
This is a helper for when we host the project on the flex server from hostpoint.
- Login to the hostpoint admin.
- go to the server (adufezuk)
- go to websites
- press new website
- choose a domain name
- as configuration for nginx choose
Nginx Custom Mode (Proxy auf eigene Applikation) - as port choose one which is not taken
# nuxt.config.js
Also important could be how to configure a port otherwise we don't know on which port the project is running. Therefore set in the .env.production file a variable PORT with the port you want. And in the nuxt.config.js add:
server: {
port: process.env.PORT // default: 3000
},
2
3
# .env file
When the project is deployed go to the staging and prod folder and add a .env file with the matching port you defined in hostpoint.
# Why we need to install the node_modules
Because we don't have a standalone build yet. Standalone merge request (opens new window) is merged but I tested and somehow it didn't work. So I wait until Standalone Documentation (opens new window) is finished so I can test again.