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

upd(create_kci_k8s_azure_build.sh): Add token for storage #192

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions playbooks/production/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
gather_facts: true
become: true
roles:
- common
- webserver
95 changes: 95 additions & 0 deletions playbooks/production/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
- name: Update apt cache
apt: update_cache=yes cache_valid_time=3600

- name: Install packages
apt: name={{ item }}
with_items:
- git
- docker.io
- docker-compose
- python3-pip
- python3-venv
- curl
- libssl-dev
- pkg-config

#- name: Add to fstab
# ansible.builtin.lineinfile:
# path: /etc/fstab
# line: "UUID=64d72737-f1de-4f67-a22a-f693a79f228f /data ext4 defaults,nofail 0 2"
# state: present

- name: Mount the disk
ansible.posix.mount:
path=/data src=UUID=64d72737-f1de-4f67-a22a-f693a79f228f fstype=ext4 state=mounted
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is a volume in Azure. I think this UUID should be retrieved first with k8s_info task, exported as a fact and only then used here (I'll look up similar task as an example later - ping me if I forget to do so 😅)

Copy link
Member Author

Choose a reason for hiding this comment

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

It is legacy block device i want to reuse, unfortunately this is old storage stuff i have to migrate first, but then system will be cleaned up from legacy things and recipe will change.
Main purpose of this initial recipe how to image system fast and bring up on new distro with minimum downtime (and reverse if something doesnt work).
Then, final recipe after i will finish storage cleanup will be done.

# its ok if it fails (for simulation purposes)
ignore_errors: true


- name: Create data directories if they don't exist
ansible.builtin.file: path={{ item.data_dir }} state=directory
with_items: "{{ vhosts }}"

- name: Create data directory for storage
ansible.builtin.file: path=/data/storage state=directory

- name: Verify if Rust installed
shell: rustc --version
register: rust_installed
ignore_errors: true

- name: Install Rust
when: rust_installed.rc != 0
shell: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
args:
creates: /root/rustup-init

- name: Is cargo in PATH?
shell: echo $PATH | grep -q "$HOME/.cargo/bin"
register: cargo_in_path
ignore_errors: true

- name: Add cargo to PATH
when: cargo_in_path.rc != 0
shell: echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> /root/.bashrc
args:
creates: /root/.bashrc

- name: Delete old kernelci-storage directory
file: path=/root/kernelci-storage state=absent
ignore_errors: true

- name: Clone storage repo
git:
repo: https://github.com/nuclearcat/kernelci-storage.git
dest: /root/kernelci-storage
update: true
force: true

- name: Build Rust program kernelci-storage
shell: cd /root/kernelci-storage && cargo build --release
args:
creates: /root/kernelci-storage/target/release/kernelci-storage

- name: Install kernelci-storage to /usr/local/bin
shell: mv /root/kernelci-storage/target/release/kernelci-storage /usr/local/bin
Comment on lines +36 to +75
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest setting up kernelci-storage releases externally and just retrieving the binary to the servers.

This way we limit software deployed on the server to reduce potential attacks surface and overall clutter in the systems ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's great to have kernelci-storage now packaged into Docker container image, it should be a good fit as a replacement for these tasks


- name: Create kernelci-storage config from template
template:
src: kernelci-storage.toml.j2
dest: /etc/kernelci-storage.toml

- name: Create systemd service
template:
src: kernelci-storage.service.j2
dest: /etc/systemd/system/kernelci-storage.service

- name: Reload systemd
systemd:
daemon_reload: true

- name: Start and enable kernelci-storage service
systemd:
name: kernelci-storage
enabled: true
state: started
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# kernelci-storage systemd service file
[Unit]
Description=kernelci-storage
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/kernelci-storage -c /etc/kernelci-storage.toml
Restart=always
RestartSec=5
WorkingDirectory=/data/storage

[Install]
WantedBy=multi-user.target

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jwt_secret=""
[azure]
account=""
key=""
container="hotstorage"
sastoken=""
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions playbooks/production/roles/webserver/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- name: Reload nginx
service: name=nginx state=reloaded
10 changes: 0 additions & 10 deletions playbooks/production/roles/webserver/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
- name: Update apt cache
apt: update_cache=yes cache_valid_time=3600

#- name: Mount the disk
# mount: path=/data src=UUID="64d72737-f1de-4f67-a22a-f693a79f228f" fstype=ext4 state=mounted

- name: Create data directories
file: path={{ item.data_dir }} state=directory
with_items: "{{ vhosts }}"

- name: Install nginx package
apt: name=nginx state=present

Expand Down