-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from stakater-docker/git-cloner
git cloner
- Loading branch information
Showing
5 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM debian:stretch | ||
|
||
RUN apt-get update && apt-get install -y git | ||
|
||
RUN mkdir /root/.ssh/ && \ | ||
mkdir /repository && \ | ||
touch /root/.ssh/known_hosts && \ | ||
echo "\nStrictHostKeyChecking no" >> /etc/ssh/ssh_config | ||
|
||
ADD init.sh / | ||
RUN chmod +x /init.sh | ||
|
||
# Clean up | ||
RUN apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
CMD ["/init.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env groovy | ||
@Library('github.com/stakater/fabric8-pipeline-library@master') _ | ||
|
||
pushDockerImage { | ||
dockerRegistryURL = "docker.io" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Mark Hilton | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,45 @@ | ||
# git-cloner | ||
Dockerfile for git-cloner | ||
|
||
Docker image to clone requested github or bitbucket repository. | ||
|
||
## Use case | ||
|
||
Kubernetes deployments where init containers usually copy/move code from docker container into emptyDir volume to share between other deployment containers. | ||
|
||
In case of push to deploy instead of waiting for the Docker container to be build with a specific repository tag, use this universal container to specify deployment SSH key file authorized to clone requested repository code from specified branch or tag. | ||
|
||
## Environment variables | ||
|
||
### required | ||
`REPO_LINK` - github or bitbucket repository SSH clone link | ||
|
||
It is also required to mount a volume where the repository will be cloned from local file system into container `/repository` folder. | ||
|
||
In case of private repositories you also have to mount deployment SSH key authorized to clone code repository | ||
|
||
### optional | ||
`TAG` - clone specified tag | ||
|
||
`BRANCH` - clone specified branch (defaults to master) | ||
|
||
`REPO_KEY` - RSA key filename (defaults to id_rsa) | ||
|
||
if cloning using repository username/password instead SSH deployment key, please provide `REPO_LINK` without leading `https://` | ||
|
||
`REPO_USER` - authorized user to clone requested repository | ||
|
||
`REPO_PASS` - authorized user password to clone requested repository | ||
|
||
|
||
## Example run | ||
|
||
``` | ||
docker run --rm -ti \ | ||
-v /path/to/clone/repository:/repository \ | ||
-v /path/to/authorized/id_rsa:/key:ro \ | ||
-e REPO_LINK=crunchgeek/git-clone | ||
-e REPO_BRANCH=master | ||
-e REPO_TAG=1.0.0 | ||
crunchgeek/git-clone | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$REPO_LINK" ]; then | ||
echo -e "\033[1;91mERROR:\033[0m REPO_LINK env variable is required" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$REPO_BRANCH" ]; then | ||
export REPO_BRANCH=master | ||
fi | ||
|
||
if [ -z "$REPO_KEY" ]; then | ||
export REPO_KEY=id_rsa | ||
fi | ||
|
||
echo "repository : $REPO_LINK" | ||
echo "branch : $REPO_BRANCH" | ||
# check if credentials files exist | ||
if [[ -f "/key/$REPO_KEY" ]] ; then | ||
echo "key file : $REPO_KEY" | ||
cp /key/$REPO_KEY /root/.ssh/id_rsa | ||
chmod 600 /root/.ssh/id_rsa | ||
ssh-keyscan -H gitlab.com >> /root/.ssh/known_hosts | ||
fi | ||
|
||
if [ ! -z "$REPO_USER" ] && [ ! -z "$REPO_PASS" ]; then | ||
# clone with repository username & password | ||
echo "credentials: username and password" | ||
git clone -b $REPO_BRANCH https://$REPO_USER:$REPO_PASS@$REPO_LINK /repository | ||
elif [[ ! -f "/root/.ssh/id_rsa" ]] ; then | ||
echo -e "\033[1;91mERROR:\033[0m REPO_USER, REPO_PASS env variables or SSH deployment key missing" | ||
exit 1 | ||
else | ||
# clone public repository or using ssh deployment key | ||
echo "credentials: RSA key" | ||
git clone -b $REPO_BRANCH $REPO_LINK /repository | ||
fi | ||
|
||
if [ ! -z "$REPO_TAG" ]; then | ||
cd /repository && \ | ||
echo "checking out repository tag: $REPO_TAG" | ||
git checkout tags/$REPO_TAG | ||
fi | ||
|