In order to use Gitlab CI/CD we need to create a file .gitlab-ci.yml
with the following contents:
before_script:
- apk update && apk add openssh rsync
stages:
- build
- deploy
build:
image: node:lts-alpine3.14
stage: build
only:
- main
script:
- npm i --progress=false
- npm run generate
artifacts:
expire_in: 1h
paths:
- .output
deploy:
image: alpine
stage: deploy
only:
- main
script:
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- rsync -rav --delete .output/public/. user@serveraddress:/srv/www/directory/
.output
directory as artifact (.output/public) was dist in Nuxt 2 / Content V1.rsync
to transfer contents of .output/public
in to our production server.Also don't forget to setup a variable SSH_PRIVATE_KEY
in your gitlab repo.
Go to Settings > CI/CD > Variables:
Use cat ~/.ssh/id_rsa | pbcopy
to save your private key in a clipboard (if you're on a Mac), then paste it in a variable, just as on a screenshot above.