-
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.
- Loading branch information
Showing
37 changed files
with
267 additions
and
205 deletions.
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
version: '3' | ||
services: | ||
|
||
gitlab-docker: | ||
build: ./gitlab-docker | ||
ports: | ||
- "443:443" | ||
- "80:80" | ||
- "2222:22" | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 4G | ||
reservations: | ||
memory: 4G | ||
gitlab-setup: | ||
build: ./gitlab-setup | ||
|
||
jenkins-docker: | ||
build: ./jenkins-docker | ||
environment: | ||
# todo read this from common volume ../gitlab-docker/setup/personal-access-token.txt | ||
- personal_access_token=$personal_access_token | ||
volumes: | ||
# Share your maven repo and ssh keys to access company resources | ||
- ~/.m2:/var/jenkins_home/.m2 | ||
- ~/.ssh:/var/jenkins_home/.ssh | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
ports: | ||
- 8080:8080 | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 4G | ||
reservations: | ||
memory: 4G |
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
FROM gitlab/gitlab-ce:latest | ||
COPY config/gitlab.rb /etc/gitlab/gitlab.rb |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
FROM ubuntu:20.04 | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y software-properties-common && \ | ||
add-apt-repository -y ppa:deadsnakes/ppa && \ | ||
apt-mark hold python2 python2-minimal python2.7 python2.7-minimal libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib && \ | ||
apt-get install -y \ | ||
python3.9 \ | ||
python3-pip \ | ||
python-is-python3 \ | ||
curl \ | ||
gettext-base \ | ||
git \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip3 install requests beautifulsoup4 lxml | ||
|
||
RUN git config --global user.email "noone@nowhere.com" && \ | ||
git config --global user.name "Provisioning Script" | ||
|
||
COPY . /bootstrap | ||
|
||
CMD ["/bootstrap/main.sh"] | ||
|
2 changes: 2 additions & 0 deletions
2
gitlab-docker/setup/add-ssh-key.sh → gitlab-setup/add-ssh-key.sh
100755 → 100644
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,5 +1,7 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
source config.txt | ||
export $(cut -d= -f1 config.txt) | ||
token=$(cat personal-access-token.txt) | ||
|
File renamed without changes.
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,4 @@ | ||
gitlab_host_name=gitlab-docker | ||
gitlab_host=http://$gitlab_host_name | ||
gitlab_user="root" | ||
gitlab_password="thepassword" #From gitlab.rb |
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
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
gitlab-docker/setup/global-settings.sh → gitlab-setup/global-settings.sh
100755 → 100644
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,5 +1,7 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
source config.txt | ||
export $(cut -d= -f1 config.txt) | ||
token=$(cat personal-access-token.txt) | ||
|
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,14 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
cd "$(dirname "$0")" | ||
|
||
source config.txt | ||
export $(cut -d= -f1 config.txt) | ||
|
||
./personal_access_token.py > personal-access-token.txt | ||
./global-settings.sh | ||
./add-ssh-key.sh | ||
./create-projects.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,89 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
https://github.com/vitalyisaev2/gitlab_token | ||
Script that creates Personal Access Token for Gitlab API; | ||
Tested with: | ||
- Gitlab Community Edition 10.1.4 | ||
- Gitlab Enterprise Edition 12.6.2 | ||
- Gitlab Enterprise Edition 13.4.4 | ||
""" | ||
import os | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from urllib.parse import urljoin | ||
|
||
endpoint = os.environ.get('gitlab_host') or 'http://gitlab-docker' | ||
root_route = urljoin(endpoint, "/") | ||
sign_in_route = urljoin(endpoint, "/users/sign_in") | ||
pat_route = urljoin(endpoint, "/-/profile/personal_access_tokens") | ||
|
||
login = os.environ.get('gitlab_user') or 'root' | ||
password = os.environ.get('gitlab_password') or 'thepassword' | ||
|
||
|
||
def find_csrf_token(text): | ||
soup = BeautifulSoup(text, "lxml") | ||
token = soup.find(attrs={"name": "csrf-token"}) | ||
param = soup.find(attrs={"name": "csrf-param"}) | ||
data = {param.get("content"): token.get("content")} | ||
return data | ||
|
||
|
||
def obtain_csrf_token(): | ||
r = requests.get(root_route) | ||
token = find_csrf_token(r.text) | ||
return token, r.cookies | ||
|
||
|
||
def obtain_authenticity_token(cookies): | ||
r = requests.get(pat_route, cookies=cookies) | ||
soup = BeautifulSoup(r.text, "lxml") | ||
token = soup.find('input', attrs={'name': 'authenticity_token', 'type': 'hidden'}).get('value') | ||
return token | ||
|
||
|
||
def sign_in(csrf, cookies): | ||
data = { | ||
"user[login]": login, | ||
"user[password]": password, | ||
"user[remember_me]": 0, | ||
"utf8": "✓" | ||
} | ||
data.update(csrf) | ||
r = requests.post(sign_in_route, data=data, cookies=cookies) | ||
token = find_csrf_token(r.text) | ||
return token, r.history[0].cookies | ||
|
||
|
||
def obtain_personal_access_token(name, expires_at, csrf, cookies, authenticity_token): | ||
data = { | ||
"personal_access_token[expires_at]": expires_at, | ||
"personal_access_token[name]": name, | ||
"personal_access_token[scopes][]": "api", | ||
"authenticity_token": authenticity_token, | ||
"utf8": "✓" | ||
} | ||
data.update(csrf) | ||
r = requests.post(pat_route, data=data, cookies=cookies) | ||
soup = BeautifulSoup(r.text, "lxml") | ||
token = soup.find('input', id='created-personal-access-token').get('value') | ||
return token | ||
|
||
|
||
def main(): | ||
csrf1, cookies1 = obtain_csrf_token() | ||
# print("root", csrf1, cookies1) | ||
csrf2, cookies2 = sign_in(csrf1, cookies1) | ||
# print("sign_in", csrf2, cookies2) | ||
authenticity_token = obtain_authenticity_token(cookies2) | ||
|
||
name = "Provisioner" | ||
expires_at = "" | ||
token = obtain_personal_access_token(name, expires_at, csrf2, cookies2, authenticity_token) | ||
print(token) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.