---
# System prepended metadata

title: Gitlab CI/CD for vue / nuxt app
tags: [' gitlab-ci', ci-cd, ' nuxt', ' vue']

---

---
tags: ci-cd, gitlab-ci, vue, nuxt
---

# Gitlab CI/CD for vue / nuxt app


## Variables

- `SSH_PRIV_KEY`
- `SSH_STAGING_USER`
- `SSH_STAGING_HOST`
- `APP_STAGING_PATH`

## Example

### Nuxt Static
```yaml=
stages:
  - install
  - build
  - deploy
  
npm_install:
  stage: install
  image: node:14
  cache:
    key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
    paths:
      - node_modules/
    policy: push
  script:
    - npm ci
  only:
    refs:
      - master
    changes:
      - package-lock.json
      
build_dev:
  stage: build
  image: node:14
  cache:
    key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
    paths:
      - node_modules/
    policy: pull-push
  script: 
    - '[[ -d "./node_modules" ]] || npm ci'
    - npm run generate
  artifacts:
    expire_in: 14 days
    paths:
      - dist
  only:
    - master
    
deploy_dev:
  stage: deploy
  image: kroniak/ssh-client
  before_script:
    - "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_PRIV_KEY")
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh/config'
    - apk add rsync
  variables:
    SSH_HOST: $SSH_STAGING_USER@$SSH_STAGING_HOST
  script:
    - rsync -rvz dist/ $SSH_HOST:$APP_STAGING_PATH
  only:
    - master


```