Get specific directory of included project in gitlab-ci - deployment

My gitlab-ci.yaml:
stages:
- linter
- build
- deploy
include:
- project: 'infrastructure/ansible-repository'
ref: '1.0.0'
file: '/project-pipeline.yml'
In the project-pipeline.yml there's a before_script: where I need to access a directory from the infrastructure/ansible-repository. At the moment I git clone the whole repository.
My Question: is there an include for a directory or something like that?

It seems you are looking for a way to download a sub directory from a remote repository. Based on which repository hosting platform (E.g. GitLab, GitHub, BitBucket and ...) you used Or your interaction with that directory there are many solutions. Such as git archive, git clone --filter, svn tool, wget, sparse checkout and so on, which all
described in this helpful post:
How do I clone a subdirectory only of a Git repository?

Related

How to specify the dockerfile path in azure devops

I have created a pipeline in azuredevops for .NET project.
My .sln file and docker file are present in different git repos.
How can I specify the dockerfile path in my azurepipeline.yml file.
Since your .sln file and docker file are in different git repos, you need to check out two git repos in Yaml file.
If your two git repos are in the same organization, you could directly add check out step in Steps.
For example:
steps:
- checkout: self
- checkout: git://Test Project/Docker Repo#master
Explaination:
The first checkout step is used to check out the repo where the yaml file is located (e.g. sln repo).
The second checkout step is used to checkout another repo(e.g. dockerfile repo).
Then two Repos will be downloaded to the $(Build.SourcesDirectory) (C:\agent_work\1\s)
So the dockerfile path could be $(Build.SourcesDirectory)\RepoName\...\Dockerfile.
If two git repos are in different resource (e.g. github , other organizaitons) , you need to add repo resource and checkout the repo.
Here is the doc about Use multiple repositories in your pipeline.

How to import a specific project from github

How to import a specific project from github ? I dont want to clone the entire repository
I just want to clone only a portion of repository .
For eg this url https://github.com/eugenp/tutorials
has many projects but I just want to clone only spring-boot-crud project .
Here is the url for spring-boot-crud project.
https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/spring-boot-crud
Thank you .
You can look into a git sparse-checkout: that command is made to checkout only part of a Git repository. This assume the latest Git 2.26 though.
And I mean Git-core, as in Git SCM, not Egit (which does not support the new sparse-checkout command)
Even though the command is new and still experimental, it should be useful in your case.
git clone --no-checkout /url/a/repo
cd repo
git sparse-checkout init --cone
git sparse-checkout set spring-boot-modules/spring-boot-crud
Then open the relevant project in your Eclipse.
Create a project in the Git repo (.project, in the root folder of your repo)
That will give you:
git clone -n https://github/git/git git2
cd git2
git sparse-checkout init
git sparse-checkout set Documentation
At this point, you have the repository git/git with only the folder Documentation checked out (everything else is not in the working tree)
# create an empty project in C:\path\to\git2 in Eclipse
As you can see, all the other files not checked out are not displayed in the Git staging view. Only the ones currently checked out and modified are listed.
The first step must be done in command-line because JGit does not support the sparse-checkout directive (see but 383772 and change 33)

Any way to put my hook to github repo?

Can I achieve it so that after pulling a repo from github the hooks has existed in .git/hooks directory?
Not directly, as that would represent a security risk (you don't know what those hook scripts are doing)
You can try and:
version a file (or files) representing your hooks in your git repo
version a .gitattribute declaring a content filter driver (smudge script), which will trigger on git checkout.
in that smudge script, copy those files into your .git/hooks
(image from "Customizing Git - Git Attributes", from "Pro Git book")
But even in that case, you would need to activate that smudge filter with a git config command first (which can be a global config, so done before cloning the repo)
git config --global filter.hooks.smudge 'script_to_copy_hooks'

clone a specific branch from git through ansible playbook

I am using ansible to deploy my app. I am cloning the app from github using the following:
- name: Deploy site files from Github repository
sudo: yes
git: repo=git#github.com:xyz/abc.git dest=/home/{{deploy_user}}/{{app_name}} key_file=/home/ubuntu/.ssh/id_rsa accept_hostkey=yes force=yes
I want to clone a specific branch from the repository. I read the documentation of ansible but couldn't find any option to clone a specific branch. It has an option to clone a version but not branch.
From the documentation:
version
What version of the repository to check out. This can be the full 40-character SHA-1 hash, the literal string HEAD, a branch name, or a tag name.
(emphasis mine)
Use version, here's the example from the docs:
- git:
repo: git://foosball.example.org/path/to/repo.git
dest: /srv/checkout
version: dev

How do I configure GitHub to use non-supported Jekyll site plugins?

I just created a great gallery for my Jekyll blog which builds perfectly on my localhost:4000. However, GitHub pages doesn't support the Jekyll Gallery Generator plug-in I am using: https://github.com/ggreer/jekyll-gallery-generator
I read about the alternative method of hosting Jekyll on a traditional host using FTP (uploading the _site directory) http://jekyllrb.com/docs/deployment-methods/ However, rather than reconfigure my entire site and hosting, It would be great if GitHub Pages could be used somehow even though I'm using a non-supported plugin.
What is a workaround for this?
Depending if you deal with a User/Organization (UO) site or a Project site (P), do :
from your working folder git init
git remote add origin git#github.com:userName/userName.github.io.git (UO) or git remote add origin git#github.com:userName/repositoryName.git (P)
jekyll new . creates your code base
in _config.yml, set the baseurl parameter to baseurl: '' (UO) or baseurl: '/repositoryName' (P)
in .gitignore add _site, it will be versioned in the other branch
jekyll build will create the destination folder and build site.
git checkout -b sources (UO) or git checkout master (P)
git add -A
git commit -m "jekyll base sources" commit your source code
git push origin sources (UO) or git push origin master (P) push your sources in the appropriate branch
cd _site
touch .nojekyll, this file tells gh-pages that there is no need to build
git init init the repository
git remote add origin git#github.com:userName/userName.github.io.git (UO) or git remote add origin git#github.com:userName/repositoryName.git (P)
git checkout master (UO) or git checkout -b gh-pages (P) put this repository on the appropriate branch
git add -A
git commit -m "jekyll first build" commit your site code
git push origin master (UO) or git push origin gh-pages (P)
You now have something like Octopress does. Look at their rake file, there are some nice comments inside.
Better way is to configure Travis to automate deployment of jekyll with non-supported plugins. Follow Travis getting started guide to enable Travis for your repo.
Create script/cibuild with the following content
#!/usr/bin/env bash
set -e # halt script on error
bundle exec jekyll build
touch ./_site/.nojekyll # this file tells gh-pages that there is no need to build
Create .travis.yml with the following content (modify as required)
language: ruby
rvm:
- 2.3.3
before_script:
- chmod +x ./script/cibuild # or do this locally and commit
# Assume bundler is being used, therefore
# the `install` step will run `bundle install` by default.
script: ./script/cibuild
# branch whitelist, only for GitHub Pages
branches:
only:
- master
env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer
sudo: false # route your build to the container-based infrastructure for a faster build
deploy:
provider: pages
skip_cleanup: true
keep-history: true
local_dir: _site/ # deploy this directory containing final build
github_token: $GITHUB_API_KEY # Set in travis-ci.org dashboard
on:
branch: master
Deployment steps (after every push):
Build will be created using our custom script script/cibuild in _site directory
_site will be pushed to gh-pages branch.
github pages will serve site as it is without building it again (because of .nojekyll file)
Reference: My repository https://github.com/armujahid/armujahid.me/ is using this method for continuous integration using Travis CI