I'm trying to deploy to Docker in my VPS everytime a new commit is made in my project in Gitlab. But I'm having an issue doing that.
I tried to install sshpass
and then scp
folder and files. But it's saying:
sshpass: Failed to run command: No such file or directory
.
The folder and files I'm trying to get from build
stage, so I dont have to build again my app.
Here's my .gitlab-ci.yml
file:
image: node:9.6.1
cache:
paths:
- node_modules/
- build/
- docker-compose.yml
- Dockerfile
- nginx.conf
stages:
- build
- test
- dockerize
build-stage:
stage: build
script:
- npm install
- CI=false npm run build
artifacts:
paths:
- build/
- docker-compose.yml
- nginx.conf
test-stage:
stage: test
script:
- npm install
- CI=false npm run test
dockerize-stage:
stage: dockerize
image: tmaier/docker-compose:latest
services:
- docker:dind
dependencies:
- build-stage
tags:
- docker
script:
- apk update && apk add sshpass
- sshpass -V
- export SSHPASS=$USER_PASS
- ls -la
- sshpass -e ssh -o stricthostkeychecking=no root@ip:/home mkdir new-super-viva
- sshpass -e scp -o stricthostkeychecking=no -r build user@ip:/home/new-folder
- sshpass -e scp -o stricthostkeychecking=no -r docker-compose.yml user@ip:/home/new-folder
- sshpass -e scp -o stricthostkeychecking=no -r nginx.conf user@ip:/home/new-folder
- sshpass -e ssh -o stricthostkeychecking=no user@ip:/home/new-folder docker-compose up --build
Here's the actual output from Gitlab CI:
$ sshpass -V
sshpass 1.06
(C) 2006-2011 Lingnu Open Source Consulting Ltd.
(C) 2015-2016 Shachar Shemesh
This program is free software, and can be distributed under the terms of the GPL
See the COPYING file for more information.
Using "assword" as the default password prompt indicator.
$ export SSHPASS=$USER_PASS
$ ls -la
total 912
drwxrwxrwx 7 root root 4096 Apr 2 13:24 .
drwxrwxrwx 4 root root 4096 Apr 2 13:24 ..
-rw-rw-rw- 1 root root 327 Apr 2 13:24 .env
drwxrwxrwx 6 root root 4096 Apr 2 13:24 .git
-rw-rw-rw- 1 root root 329 Apr 2 13:24 .gitignore
-rw-rw-rw- 1 root root 1251 Apr 2 13:24 .gitlab-ci.yml
-rw-rw-rw- 1 root root 311 Apr 2 11:57 Dockerfile
-rw-rw-rw- 1 root root 2881 Apr 2 13:24 README.md
drwxrwxrwx 5 root root 4096 Apr 2 13:20 build
-rw-rw-rw- 1 root root 340 Apr 2 13:24 build.sh
-rw-rw-rw- 1 root root 282 Apr 2 11:57 docker-compose.yml
-rw-rw-rw- 1 root root 1385 Apr 2 11:57 nginx.conf
drwxr-xr-x 1191 root root 36864 Apr 2 13:22 node_modules
-rw-rw-rw- 1 root root 765929 Apr 2 13:24 package-lock.json
-rw-rw-rw- 1 root root 1738 Apr 2 13:24 package.json
drwxrwxrwx 4 root root 4096 Apr 2 13:24 public
drwxrwxrwx 10 root root 4096 Apr 2 13:24 src
$ sshpass -e ssh -o stringhostkeychecking=no user@ip:/home mkdir new-folder
sshpass: Failed to run command: No such file or directory
ERROR: Job failed: exit code 3
Is there any way that I can copy the build
folder, docker-compose.yml
and nginx.conf
files from build-stage
to dockerize-stage
and then pass it with sshpass
to VPS? It doesnt even working to create folder with mkdir
. I also tried to create folder manually and then remove this command from .gitlab-ci.yml
but still the same output.
Just so you know I added that USER_PASS
in:
https://gitlab.com/user/project/settings/ci_cd
in environment variables and let it non-protected