Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update on demand for the git cache on build server #262

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
43fa1f0
Add script that update on demand the git cache on build server and fi…
bartoszbetka Nov 9, 2018
a42c40e
Add the `update-git-mirror.service` systemd service that control runn…
bartoszbetka Nov 13, 2018
1cb1a2a
Modify concent-builder playbooks to copy, run new files and delete ol…
bartoszbetka Nov 13, 2018
443eb27
Modify the `containers/package-builder/clone-or-update.sh.j2` script …
bartoszbetka Nov 13, 2018
983484d
Update `README.md` after changes in the deployment proccess
bartoszbetka Nov 14, 2018
2e61907
fixup! Update `README.md` after changes in the deployment proccess
bartoszbetka Nov 15, 2018
d970d68
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
6872388
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
8260fee
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
04e8656
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
7b460a7
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
88880fc
fixup! Add script that update on demand the git cache on build server…
bartoszbetka Nov 15, 2018
f52d4f2
fixup! Add the `update-git-mirror.service` systemd service that contr…
bartoszbetka Nov 15, 2018
0b329f8
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
98a4e52
fixup! Add the `update-git-mirror.service` systemd service that contr…
bartoszbetka Nov 15, 2018
77df556
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
67c2063
fixup! Add script that update on demand the git cache on build server…
bartoszbetka Nov 15, 2018
6af6780
fixup! Modify concent-builder playbooks to copy, run new files and de…
bartoszbetka Nov 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,7 @@ All the instructions below assume that you're using the remote server.

### Building containers and cluster configuration

``` bash
cd concent-deployment/concent-builder/
ansible-playbook install-repositories.yml \
--extra-vars cluster=$cluster \
--inventory ../../concent-deployment-values/ansible_inventory \
--user $user

```
ansible-playbook build-test-and-push.yml \
--extra-vars cluster=$cluster \
--inventory ../../concent-deployment-values/ansible_inventory \
Expand All @@ -171,7 +165,15 @@ ansible-playbook build-test-and-push.yml \

### Deploying secrets
Before you can deploy containers, you need to make sure that certificates, keys and passwords used to configure those containers are available on the cluster.
Deploy them with:
Upload them from your local machine with:

``` bash
cd concent-deployment/cloud/
ansible-playbook install-secrets.yml \
--extra-vars cluster=$cluster \
--inventory ../../concent-deployment-values/ansible_inventory \
--user $user


``` bash
cd concent-deployment/cloud/
Expand Down
2 changes: 1 addition & 1 deletion cloud/cluster-deploy-secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
make:
chdir: "{{ build_dir }}/concent-deployment/secrets"
params:
CONCENT_SECRET_DIR: "{{ data_dir }}/concent-secrets/{{ cluster }}"
CONCENT_SECRET_DIR: "{{ secret_dir }}/{{ cluster }}"
CLUSTER: "{{ cluster }}"

- name: Configure kubectl to operate on the right cluster
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
- hosts:
- concent-builder
vars_files:
- consts.yml
- repositories.yml
- ../concent-builder/consts.yml
- "{{ deployment_values }}/var.yml"
- "{{ deployment_values }}/var-{{ cluster }}.yml"
tasks:
- become: yes
become_user: "{{ shared_user }}"
block:
- name: Clone concent repositories
git:
repo: "{{ item.value.url }}"
dest: "{{ data_dir }}/{{ item.key }}/"
clone: yes
update: yes
bare: yes
# FIXME: Do not blindly accept the hostkey
accept_hostkey: yes
with_dict: "{{ repositories }}"

- name: Create a directory for secrets
file:
path: "{{ data_dir }}/concent-secrets/{{ item }}/"
path: "{{ secret_dir }}/{{ item }}/"
state: directory
with_items:
- "{{ cluster }}"
Expand All @@ -37,7 +25,7 @@
- name: Upload secrets
copy:
src: "{{ local_secret_dir }}/{{ cluster }}/{{ item }}"
dest: "{{ data_dir }}/concent-secrets/{{ cluster }}/{{ item }}"
dest: "{{ secret_dir }}/{{ cluster }}/{{ item }}"
owner: "{{ shared_user }}"
group: "{{ shared_user }}"
with_items:
Expand All @@ -54,7 +42,7 @@
- name: Activate the service account that has permissions to access the cluster
command: gcloud auth activate-service-account \
"{{ gke.service_account_name }}@{{ gke.project }}.iam.gserviceaccount.com" \
--key-file "{{ data_dir }}/concent-secrets/cloud/{{ gke.service_account_name }}-private-key.json"
--key-file "{{ secret_dir }}/cloud/{{ gke.service_account_name }}-private-key.json"

- name: Configure kubectl to operate on the right cluster
command: gcloud container clusters get-credentials \
Expand Down
9 changes: 7 additions & 2 deletions concent-builder/build-test-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
- concent-builder
vars_files:
- consts.yml
- repositories.yml
- "{{ deployment_values }}/var.yml"
- "{{ deployment_values }}/var-{{ cluster }}.yml"
tasks:
Expand All @@ -14,9 +13,15 @@
path: "{{ build_dir }}"
state: absent

- name: Clone or update git repositories
service:
name: update-git-mirror
state: started
become_user: root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put it in a separate block. It makes it easier to see that you're switching users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This require also add second block for task below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not have to run it as root. The whole idea with setuid was to allow normal users to run it.

EDIT: After finishing the review I see that systemctl does not let use do what we wanted to achieve. We need to use sudo after all. See my comment in the issue that explains the problem and shows what we want to do instead: #191 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, we agreed to use systemctl with sudo. We only run sudo with systemctl that is less dangerous than when we run all scripts with sudo. The systemd service control what is execute.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we agreed to use systemctl to avoid sudo (which is more problematic because it requires messing with /etc/sudoers/) and to use sudo as a last resort if systemd does not have any feature that let's you define who can run a service. It doesn't so let's go with sudo. I don't see any benefit in having a service if you need to use sudo anyway.


- name: Check out working copy of concent-deployment repositories
git:
repo: "{{ data_dir }}/concent-deployment"
repo: "{{ git_mirror_dir }}/concent-deployment"
dest: "{{ build_dir }}/concent-deployment"
version: "{{ versions['concent-deployment'] }}"
clone: yes
Expand Down
36 changes: 32 additions & 4 deletions concent-builder/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,37 @@
state: present
groups: docker

- name: Create data_dir
- name: Create git_mirror_dir and secret_dir
file:
path: "{{ data_dir }}"
path: "{{ item.name }}"
state: directory
owner: "{{ shared_user }}"
group: "{{ shared_user }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
with_items:
- { name: "{{git_mirror_dir}}", owner: root, group: root, mode: "0755" }
- { name: "{{secret_dir}}", owner: "{{ shared_user }}", group: "{{ shared_user }}", mode: "0755" }

- name: Copy scripts that update git repositories
template:
src: "{{ item.name }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: 0555
with_items:
- { name: repositories.sh, dest: /usr/local/lib/ }
- { name: update-git-mirror.sh.j2, dest: /usr/local/bin/update-git-mirror.sh }

- name: Copy service that run update git repositories script
template:
src: update-git-mirror.service.j2
dest: /etc/systemd/system/update-git-mirror.service
owner: root
group: root
mode: 0555

- name: Clone or update git repositories
service:
name: update-git-mirror
state: started
3 changes: 2 additions & 1 deletion concent-builder/consts.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
shared_user: builder
data_dir: /var/concent-data
git_mirror_dir: /var/git-mirror
secret_dir: /var/concent-secrets
build_dir: /home/{{ shared_user }}/build/{{ cluster }}
local_secret_dir: ../../concent-secrets
deployment_values: ../../concent-deployment-values
9 changes: 9 additions & 0 deletions concent-builder/repositories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash -e

declare -A repositories

repositories=(
["concent"]="https://github.com/golemfactory/concent.git"
["concent-deployment"]="https://github.com/golemfactory/concent-deployment.git"
["golem"]="https://github.com/golemfactory/golem.git"
)
bartoszbetka marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 0 additions & 7 deletions concent-builder/repositories.yml

This file was deleted.

9 changes: 9 additions & 0 deletions concent-builder/update-git-mirror.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Update git repository

[Service]
Type=oneshot
User=root
Group=root
WorkingDirectory={{ git_mirror_dir }}/
ExecStart=/usr/local/bin/update-git-mirror.sh
27 changes: 27 additions & 0 deletions concent-builder/update-git-mirror.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /bin/bash -e

source /usr/local/lib/repositories.sh
export repositories

list_of_directories=(
$(ls {{ git_mirror_dir }}/)
)

# Check list of directories in `/var/git-mirror/` path with repositories list in the `repositories.sh` file.
for directory in "${list_of_directories[@]}"; do
if [[ ! " ${!repositories[@]} " =~ " ${directory} " ]]; then
rm -rf "/var/git-mirror/$directory/"
fi
done

# Check if repositories from the `repositories.sh` file exist in `/var/git-mirror` path
# and clone or update them.
for repository in "${!repositories[@]}"; do
repository_path="/var/git-mirror/$repository/"
if [ ! -d $repository_path ]; then
git clone --mirror "${repositories[$repository]}" "$repository_path"
else
cd "$repository_path"
git fetch origin --prune
fi
done
4 changes: 2 additions & 2 deletions containers/package-builder/clone-or-update.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ repository=$1
directory=$2

if [[ "$repository" == "concent" ]]; then
repository_path=/var/concent-data/concent/
repository_path=/var/git-mirror/concent/
repository_version="{{ concent_version }}"
elif [[ "$repository" == "golem" ]]; then
repository_path=/var/concent-data/golem/
repository_path=/var/git-mirror/golem/
repository_version="{{ golem_version }}"
else
echo "The '$repository' repository does not exist"
Expand Down