Gitlab-ci file has no effect on my project - gitlab

I'm trying to auto-build/deploy my angular app to my remote server but I don't get why the gitlab-ci.yml is not working :
image: trion/ng-cli-karma
cache:
paths:
- node_modules/
before_script:
- apt-get update -qq && apt-get install -y -qq sshpass
deploy_stage:
stage: deploy
environment: Staging
only:
- master
script:
- rm ./package-lock.json
- npm install
- ./node_modules/#angular/cli/bin/ng test --progress false --single-run=true --watch=false
- ./node_modules/#angular/cli/bin/ng e2e --progress false --watch=false
- ./node_modules/#angular/cli/bin/ng build --progress false --prod
- cd dist/
- ls
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e scp -o stricthostkeychecking=no -r . myusername#myserver:/var/www/html
deploy_production:
stage: deploy
environment: Production
only:
- tags
script:
- rm ./package-lock.json
- npm install
- ./node_modules/#angular/cli/bin/ng test --progress false --single-run=true --watch=false
- ./node_modules/#angular/cli/bin/ng e2e --progress false --watch=false
- ./node_modules/#angular/cli/bin/ng build --progress false --prod
- cd dist/
- ls
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e scp -o stricthostkeychecking=no -r . myusername#myserver-prd:/var/www/html
On my Gitlab CE server, I don't see the effect of the file, there is no build job :
Am I missing a step here?

The gitlab-ci.yml file you mentioned in your question should be renamed to .gitlab-ci.yml.
GitLab CI/CD Pipeline Configuration Reference
.

Related

Gitlab Pipeline: lftp runs into a timeout

I received a notification a few days ago from my gitlab runner about a failed pipeline.
The Pipeline was working normally and nothing got changed, which makes everything a bit harder to investigate.
The specific command which causes the timeout of 1 hour is the following:
lftp -e "set ftp:ssl-allow no; mirror -R dist/ ./; quit;" -u $USER_TEST,$PASSWORD_TEST $HOST_TEST
This was working fine. I tried to troubleshoot this problem. There are a plenty of reasons out there why the timeout happens. However none of it was solving my problem.
A short brief of what the git pipeline does:
building an angular app (the dist folder's size is about 750kB)
deploying it on a server using ftp credentials
I manually went through the pipeline steps, hoping to replicate the bug, but it was working fine.
.gitlab-ci.yml:
image: node:14.15.3-alpine
cache:
paths:
- node_modules/
stages:
- build
- deploy
#DEV Stage
build_stage_dev:
stage: build
only:
refs:
- develop
cache:
paths:
- dist/
script:
- npm install --legacy-peer-deps
- npm install -g #angular/cli#11.0.5
- ng build --build-optimizer
deploy_stage_dev:
stage: deploy
environment: develop
only:
refs:
- develop
script:
- apk update && apk add openssh-client && apk add sshpass
- export SSHPASS=$PASSWORD_DEV
#command to remove all files first
#- sshpass -e ssh -o stricthostkeychecking=no $USER_DEV#$HOST_DEV rm -r /var/www/app/*
- sshpass -e scp -o stricthostkeychecking=no -r dist/* $USER_DEV#$HOST_DEV:/var/www/app
#TEST Stage
build_stage_test:
stage: build
only:
refs:
- test
cache:
paths:
- dist/
script:
- npm install --legacy-peer-deps
- npm install -g #angular/cli#11.0.5
- ng build --build-optimizer
deploy_stage_test:
stage: deploy
environment: test
only:
refs:
- test
script:
- apk update && apk add lftp
- lftp -e "set ftp:ssl-allow no; mirror -R dist/ ./; quit;" -u $USER_TEST,$PASSWORD_TEST $HOST_TEST
The DEV Stage (deploying with the ssh) is working fine. Only the test stage throws an error after 1 hour.
This is the error I receive on Gitlab: ERROR: Job failed: execution took longer than 1h0m0s seconds
Maybe any of you have experienced the same? or did "lftp" got an update and I am running into an enndless job?
Also I checked whether files are getting updated at all, the answer is no. I thought it could be an issue with "quit". But appearently nothing is getting transferred at all.

I get no such file or directory when moving dist folder contents from gitlab to aws server instance

I am new to Gitlab CI/CD and trying to fix this all day long but nothing works. I am trying to move the dist folder generated by gitlab runner after build stage to aws ec2-instance folder location. I am currently implementing CI/CD pipeline using Gitlab and this is how my .gitlab-ci.yml looks like:
# Node Image for docker on which code will execute
image: node:latest
# This is the stages / task to perfom in jobs
stages:
- build
- deploy
# caching for reuse
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- node_modules/
# This command is run before the execution of stages
before_script:
- npm install
# Job One for making build
build_testing_branch:
stage: build
script:
- node --max_old_space_size=4096 --openssl-legacy-provider ./node_modules/#angular/cli/bin/ng build --configuration=dev-build --build-optimizer
only: ['testing']
# Job Two for deploy build to server
deploy_testing_branch:
stage: deploy
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
# - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
# - apt-get update -y
# - apt-get -y install rsync
artifacts:
paths:
- dist/
script:
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- ssh -p22 ubuntu#$SERVER_IP "rm -r /usr/share/nginx/user-host/ui-user-host/dist/; mkdir /usr/share/nginx/user-host/ui-user-host/dist/"
- scp -P22 -r $CI_PROJECT_DIR/dist/ ubuntu#$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/
only: ['testing']
The build process works just fine with success confirmation, but the deployment stage fails because I get:
$scp -P22 -r $CI_PROJECT_DIR/dist/ ubuntu#$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/
/builds/user-live/ui-user-host/dist: No such file or directory
Cleaning up project directory and file based variables
So, I dont understand why its not able to locate dist folder in above location. If i correctly understand this should be available on the gitlab runner's filesystem. Is it because scp command is not right?
EDIT:
I also tried with
- scp -P22 -r dist/ ubuntu#$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/
and
- scp -P22 -r dist/* ubuntu#$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/
but no luck!
You are building your dist folder in build_testing_branch job and trying to access it in deploy_testing_branch for this to work you have to give the dist folder as artifact in build_testing_branch job (since dist is created there) and not in deploy_testing_branch.

Management of CI / CD vuejs deployments

I need help with deploying vuejs project using CI / CD gitlab.
in this case I have 3 file environments:
.env.development.local
.env.staging.local
.env.production.local
And I'm here using a different baseHref / publicPath:
/ development
/ stage
/ production
In this stage I follow the tutorial Here.
but I am still confused about how I deployed using a different env.
Usually I use the command:
Staging
    
npm run build -- --mode stage
Production
    
npm run build -- --mode production
Here is an example of the env that I made:
# Environment Local
NODE_ENV=development
BASE_URL = /development/
VUE_APP_TITLE=Website (development)
VUE_APP_END_POINT='http://localhost:8000/api/v1/'
VUE_APP_CLIENT_ID = 12341
VUE_APP_CLIENT_SECRET = 'asdASD1123s'
VUE_APP_SCOPE = '*'
VUE_APP_BASE_URL_LINK = 'http://localhost:8080'
VUE_APP_VERSION =
And this is the vue.config.js file that I have:
process.env.VUE_APP_VERSION = require('./package.json').version
module.exports = {
publicPath: process.env.BASE_URL,
"transpileDependencies": [
"vuetify"
]
}
branch that I made:
test
development
master
In gitlab-ci.yml:
build site:
image: node:6
stage: build
script:
- npm install --progress=false
- npm run build
artifacts:
expire_in: 1 week
paths:
- dist
unit test:
image: node:6
stage: test
script:
- npm install --progress=false
- npm run unit
deploy:
image: alpine
stage: deploy
script:
- apk add --no-cache rsync openssh
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
- chmod 600 ~/.ssh/id_dsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- rsync -rav --delete dist/ user#server.com:/var/www/website/
with the configuration of gitlab-ci.yml above I can only deploy local env.
I hope someone wants to share their knowledge and experience about CI / CD deploy vuejs. Or give some CI / CD vuejs tutorial references multiple environment.
Thank you very much.
I found a dockerfile in my projet if it's can help you :
FROM node:12.16.1 AS builder
RUN mkdir /app
COPY *.json /app/
COPY src /app/src
WORKDIR /app
RUN npm install
RUN npm run build
FROM nginx:1.15.8
COPY --from=builder /app/dist/ /usr/share/nginx/html
EXPOSE 80:80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
Don't forget to use multi stages docker ;)

gitlab ci pipeline failed deploy ftp

I try to build and push my react build folder with gitlab-ci.yml
Build and test passes but deploy failed with this error :
If I do the same script in my locale file, it works !
lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST
mirror: Access failed: /builds/myGitLab/myGitlabProjectName/build: No such file or directory
lftp: MirrorJob.cc:242: void MirrorJob::JobFinished(Job*): Assertion `transfer_count>0' failed.
/bin/bash: line 97: 275 Aborted (core dumped) lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST
ERROR: Job failed: exit code 1
Here is my all yml file :
image: node:13.8
stages:
- build
- test
- deploy
build:
stage: build
script:
- npm install
- npm run build
test:
stage: test
script:
- yarn
- yarn test
deploy:
script:
- apt-get update && apt-get install -y lftp
- lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST
enter code here
I 've got it ! i was started from a docker image (node) to perform those 3 stages: the build, the test and the deploy but without success but i tried doing an ls-a in the stage deploy I realized that I didn't have the build folder. Because the docker image was recreated each time, so I added artifacts to keep the buid file!
Once the job in the build stage is "done".it keep in a variable buid readable for next job also the deploy !
image: node:13.8
stages:
- build
- test
- deploy
build:
stage: build
script:
- npm install
- npm run build
only:
- master
artifacts:
paths:
- build
test:
stage: test
script:
- yarn
- yarn test
deploy:
stage: deploy
before_script:
- apt-get update -qq
script:
- apt-get install -y -qq lftp
- ls -a
- lftp -e "set ssl:verify-certificate false; mirror --reverse --verbose --delete build/ ./test2 ; quit" -u $USERNAME,$PASSWORD $HOST
only:
- master
I have a part of the answer, but i would like to do something better
Actually, i understood what is going on. On every stage the docker image build then after the build on the test and deploy, there is no more build folder.
I don't know how to persit the docker image witch is node to every stages.
Any help will be welcome.
To make it works i have done every script in one stage this way:
image: node:13.0.1
stages:
- production
build:
stage: production
script:
- npm install
- npm run build
- npm run test
- apt-get update -qq && apt-get install -y -qq lftp
- lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST
only:
- master

npm: command not found - Gitlab CI specific runner

I am running gitlab-runner on my server, I am not using docker for deployment. I am trying to achieve the deployment on a remote server by doing ssh to the server. This is my .gitlab-ci.yml file -
stages:
- deploy
pre-staging:
stage: deploy
environment:
name: Gitlab CI/CD for pre-staging deployment
url: "$REMOTE_SERVER"
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- 'echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- ssh-add <(echo "$REMOTE_PVT_KEY")
- ssh ubuntu#"$REMOTE_SERVER" "cd deployment_container; npm --version ;rm -rf static; source deploy.sh"
- echo "Deployment completed"
only:
- megre_requests
- pre-staging
tags:
- auto-deploy
My pipeline is failing with error npm: command not found. I have proper environment for npm on my ssh-ed server. I am trying to deploy the Django-react application.
I have already tried using image: node:latest.
npm is installed using nvm
Can somebody help me resolve this?
Try and replace the ssh step with:
ssh ubuntu#"$REMOTE_SERVER" "pwd; cd deployment_container; echo $PATH"
If this "deployment" (which won't do anything) completes, it means npm is not accessible in the default PATH defined in the SSH session.
In this we have to give npm access to all users by executing below command,
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
This resolved my issue of npm: command not found
You can try this one.
stages:
- build
- deploy
deploy-prod:
image: node:12.13.0-alpine
stage: deploy
script:
- npm i -g firebase-tools

Resources