Uploading projects from local computer to server by using Gitlab - upload

I am completely new to Gitlab because previously I upload project to server using Filezilla. But now I have finished my Laravel projects in my local computer, and I would like to upload it to my could hosting. Currently my project is stored in c:\\xampp\htdocs\myproject.
Please tell me command line step-by-step to achieve this? I am using Putty on window. I can't understand it by reading existing tutorial.

I use DigitalOcean.com's server and yes I registered on gitlab.com to store/upload my project.
As a first approach, you can push directly to DigitalOcean, as describe in this tutorial:
clone your GitLab repo as a bare repo on your DigitalOcean instance (VPS: Virtual Private Server or Droplet)
cd
git clone --bare https://gitlab.com/<yourUsername>/<yourRepo.git>
add a post-receive hook similar to this auto-deploy article
That is:
cat > /home/rails/rails_project.git/hooks/post-receive
(Copy-paste the following lines)
#!/bin/sh
echo "-----------------------------------"
echo "Post receive hook: Updating website"
export GIT_WORK_TREE=/path/to/yourProject
export GIT_DIR=/home/yourUser/yourRepo.git
cd $GIT_WORK_TREE
git pull
git checkout master -f
(type Ctrl+D to exit)
Depending on your deployment path, you might have to execute the git commands as root, but it is best if you can keep your deployment as your username and not root.
But if you don't want to push to DigitalOcean, only to GitLab, you can use instead Git-Auto-Deploy.
Then you can push to GitLab, and that will trigger a deployment to your VPS.
When commits are pushed to your Git repository, the Git server will notify Git-Auto-Deploy by sending a HTTP POST request with a JSON body to a pre configured URL (your-host:8001).
The JSON body contains detailed information about the repository and what event that triggered the request.
Git-Auto-Deploy parses and validates the request, and if all goes well it issues a git pull.
Additionally, Git-Auto-Deploy can be configured to execute a shell command upon each successful git pull, which can be used to trigger custom build actions or test scripts.

Related

Jenkins Build Trigger after each commit to Github

I want to set in Jenkins jobs triggering Build after each commit
I dont have access to Setting in my repository on Github, so I don't have possibility using WebHook.
What is the best/.easy way to set this in other way?
I have jobs for private repository Github, and clone project by SSH
I also using Github Oauth Token
Jenkins Continuous Integration Server is on running on a Ubuntu host
You can use local git hook pre-push. It runs after you issue the "git push" command. (but executes before pushing)
See example: pre-push hook

Jenkins configuration with remote live server

I want to know how to configure Jenkins with my live preprod instance server ?
Let me to explain you my process and tell me if I'm right and if that's not the good way to do.
1) I have my project project-1 in a server: /var/www/preprod/project-1, this project is in Magento Cms so it contains many files.
2) I copied this project project-1 in a repo Git, repo = project-1.
3) I cloned this project from this repo Git to my local machine: MAMP/htdocs/project-1.
4) I installed Jenkins, and I configured it with git, So when I do some push, Jenkins do a build automatically.
Now what I want to do is after the build, I want Jenkins to upload these changes to my live preprod server, whether automatically and manually.(I want to know the method to do it manually and automatically).
With this method, I develop in my local server, so when I finish some task and it's done, I push it to Git to have the changes history, and after that my need is to push it to the live server.
So tell me please if I'm using the right method, if it's a good practice and what I miss for this continuous deployment & delivery.
You can push it to the server using the Publish over SSH command if your doing a freestyle job https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin, If you are doing an pipeline then you can do a simple scp command...
you can run this after the build is completed and it will run it automatically for you ...
Manually you will be notified when a build is done then you would copy it into your server using the normal way you would do it i.e.copy and paste...
Jenkins is a automation server. The whole point of using jenkins is to automate things so that you "manual" intervention is not required. So automate it where ever possible.
Hope it helps :)

Forgot to create a new repo at Bitbucket before creating one at local machine

I am learning RoR from Michael Hartl's tutorial. I created a new repository with git init and continued with:
$ git remote add origin git#bitbucket.org:ashsean46/sampleapp.git
I forgot to initialize a repo at Bitbucket before running this command.
I deployed the app on heroku and continued with the tutorial until this command stumped me:
$ git push -u origin statpage
ssh: Could not resolve hostname bitbucket.org: no address associated with name
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
(here statpage is my side branch) I have done this mistake before but the repo automatically showed up at Bitbucket after one day. Also I tried running the master branch code on heroku and everything works fine.
Why does this happen?
Is there any way of displaying the created repo at Bitbucket?

After changing Maricurial url in hgrc, jenkins stuck on pull

My repository url was changed so I updated hgrc file with new url. I also updated new url in jenkins job.
Now when I am building the job, it hangs with the following output
-----------------Console Output-------------------
Started by user user123
Building in workspace D:\jenkins\jobs\api\workspace
[workspace] $ "C:\Program Files\TortoiseHg\hg.exe" showconfig paths.default
[workspace] $ "C:\Program Files\TortoiseHg\hg.exe" pull --rev branch
And it will never move forward. If i run the same command on cmd
"C:\Program Files\TortoiseHg\hg.exe" pull --rev branch
It works fine with following output
pulling from ssh://repos-url/repos-name
no changes found
But jenkins hangs on this command. Need some help to move forward.
Thank you
It sounds to me more a jenkins configuration question than a mercurial one :)
Are you talking about the identical clone of the repository? Does the jenkins user have read permissions on the repository it pulls from? Is it configured to pull via ssh, too and does it have the necessary ssh credentials? Or, if pulling via http, is hgweb running on the repo or another webserver to support hg?
Also, unless your project is called 'api', the URL looks strange to me: Jenkins (by default) has its clones in /jenkins-home-directory/jobs/projectname/workspace
As I mentioned in my question that I recently changed repository url. The issue was that new server's key was not cached in the registry where jenkins was hosted.
Resolution:
I logged in to the administrator account(same account used by jenkins) on my server through RDP and on the other side I started building the job in jenkins. When the console output came to this line
[workspace] $ "C:\Program Files\TortoiseHg\hg.exe" pull --rev branch
RDP window showed me an alert which was
Putty Security Alert
I pressed Yes and I saw jenkins console is now progressing and build was successful after that.

update files from local to remote with git and capistrano

I have deployed my app in remote server with capistrano and git. I'm novice with capistrano and git, and my question is:
e.g.
I make a change and add code in any file from my local project, e.g. change 2 lines in controller or model or view or css or js or routes.rb or devise.rb...etc.
before I had a ftp and replace the files via ftp, I see that this way is not good for rails.
I want to know how can I send those changes to my production remote app in my vps remote server.
I have tried:
cap deploy
but is very very slowly and overload the server. I dont think that is way is correct
I dont know if this must be doing with capistrano or with git e.g. I suposse with git is:
git remote add origin user#ip.ip.ip.ip/~/project
git push origin master
Its possible use this code for deploy changes in production app in remote server? or have I that use capistrano for make changes in app in production server?
Sorry for mi ignorance but I'm novice with rails and capistrano and git.
Thank you
You can deploy code using either just git itself or with capistrano (together with git).
Using just Git
You only need to run "git remote add origin user#ip.ip.ip.ip/~/project" one time, after this your settings are already saved. If you want to see your remote git repos, just type "git remote"
After you have made your changes and run git commit (I assume you know how to do this already), then run "git push origin master" to push all your changes to the remote repo.
Now SSH to your remote server, eg "ssh myuser#mydomain.com" (for Mac) or using Putty (for Windows)
Once logged in to the remote server, navigate to your app root folder.
if you have never cloned your git repo to your remote server before, you will first need to run "git clone "
otherwise, just run "git pull origin master". This will fetch and pull the changes from Step 2 above to your remote server. And now you are finished!
Advantage: This approach only pulls your most recent changes to your remote server, so it is much faster.
Disadvantage: You have to manually run a lot of commands to SSH to server and git pull.
Using Capistrano
You mention you can run "cap deploy" so I assume your Capistrano setup is fine. This approach is slower because it pulls your latest commit (and potentially your whole git repo) when you deploy.
If you want to speed up your Capistrano deployment, you can add the following to your deploy.rb. This keeps a copy of your git repo on your remote server instead of doing a full git clone upon every deploy.
set :deploy_via, :remote_cache
Advantage: Just type "cap deploy" and deployment happens (plus all the capistrano benefits of deployment rollback etc)
Disadvantage: Slower than just git pull.

Resources