Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

PMM-8306 migrate ami ova to docker #343

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
9 changes: 5 additions & 4 deletions packer/ansible/pmm2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
- name: Create PMM2 image
hosts: default
become: true
roles:
- lvm-init
tasks:
# - name: Enable epel repo
# command: amazon-linux-extras install -y epel
- name: Install packages
package:
name:
- docker
- python3-pip
- python3
- lvm2

- name: Install docker Python API
pip:
Expand Down Expand Up @@ -126,11 +127,11 @@

- name: pull the PMM image
docker_image:
name: percona/pmm-server:2.26.0
name: "{{ pmm_server_image_name }}"
source: pull

- name: Copy systemd service file to image
copy:
template:
src: pmm2.service
dest: /etc/systemd/system
owner: root
Expand Down
69 changes: 69 additions & 0 deletions packer/ansible/roles/lvm-init/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
- name: Wait until disk will be presend
nikita-b marked this conversation as resolved.
Show resolved Hide resolved
wait_for:
path: /dev/xvdb

- name: Create Volume Group
lvg:
vg: DataVG
pvs: "/dev/xvdb"

- name: Create Thin Pool
register: thin_pool
failed_when: "thin_pool is failed and 'Sorry, no shrinking of DataLV to 0 permitted' not in thin_pool.msg"
lvol:
lv: DataLV
vg: DataVG
size: 100%FREE
opts: --thinpool ThinPool -V 1G

- name: Format LVM
filesystem:
fstype: xfs
dev: /dev/DataVG/DataLV
opts: -L DATA

- name: Mount
mount:
name: "/var/run/docker"
src: LABEL=DATA
fstype: xfs
opts: defaults,nofail
nikita-b marked this conversation as resolved.
Show resolved Hide resolved
state: mounted

- name: stat /boot/grub2/grub.cfg
stat: path=/boot/grub2/grub.cfg
register: grub2_conf

- name: System Log | change /etc/default/grub
when: grub2_conf.stat.exists
replace:
dest: /etc/default/grub
regexp: 'rhgb'
replace: 'console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 xen_emul_unplug=unnecessary'
register: grub2_var

- name: System Log | run grub2-mkconfig
when: grub2_var.changed and grub2_conf.stat.exists
command: grub2-mkconfig -o /boot/grub2/grub.cfg

- name: Create dirs | Create dirs
file: path={{ item }} state=directory
with_items:
- /var/lib/cloud/scripts/per-once
- /var/lib/cloud/scripts/per-boot

- name: Data partition | Auto resize LVM
template:
src: resize-xfs-lvm
dest: /var/lib/cloud/scripts/per-boot/resize-xfs
mode: 0755

- name: Cron tasks | Add resize task to cron
cron:
name: "resize data partition"
minute: "*/5"
ademidoff marked this conversation as resolved.
Show resolved Hide resolved
user: root
job: "/var/lib/cloud/scripts/per-boot/resize-xfs"
cron_file: resizeXfs

7 changes: 7 additions & 0 deletions packer/ansible/roles/lvm-init/templates/resize-xfs-lvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

/usr/sbin/pvresize $(/usr/bin/ls /dev/sda /dev/sdb /dev/sdc /dev/xvdb /dev/nvme1n1 2>/dev/null | /usr/bin/grep -v ^$(/usr/sbin/pvdisplay -c | /usr/bin/grep ':VolGroup00:' | /usr/bin/cut -d ':' -f 1 | /usr/bin/tr -d '[:space:]' | /usr/bin/sed 's/[0-9]$//')$ | /usr/bin/grep -v ^$(/usr/bin/findmnt -f -n -o SOURCE / | /usr/bin/sed 's/[0-9]$//')$ | /usr/bin/grep -v ^$(/usr/bin/findmnt -f -n -o SOURCE /mnt/resource | /usr/bin/sed 's/[0-9]$//')$)
/usr/sbin/lvextend -l '1%VG' /dev/DataVG/ThinPool_tmeta
/usr/sbin/lvextend -l '100%VG' /dev/DataVG/ThinPool
/usr/sbin/lvextend -l '80%PVS' /dev/DataVG/DataLV
/usr/sbin/xfs_growfs -d /srv
3 changes: 3 additions & 0 deletions packer/ansible/roles/lvm-init/templates/resize-xfs-no-lvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
set -o errexit
/usr/sbin/xfs_growfs -d {{ data_partition }}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ExecStartPre=-/usr/bin/docker exec %n stop
ExecStartPre=-/usr/bin/docker rm %n
ExecStart=/usr/bin/docker run --rm --name %n \
--net host \
percona/pmm-server:2.26.0
{{ pmm_server_image_name }}

[Install]
WantedBy=default.target
9 changes: 9 additions & 0 deletions packer/pmm2.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ packer {
}
}

variable "pmm_server_image_name" {
type = string
default = "perconalab/pmm-server:dev-latest"
Copy link
Member

Choose a reason for hiding this comment

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

Do we implement this feature for internal usage or for public?

}

source "amazon-ebs" "pmm2" {
ami_name = "PMM2 Server [${formatdate("YYYY-MM-DD hhmm", timestamp())}]"
instance_type = "c4.xlarge"
Expand Down Expand Up @@ -58,6 +63,10 @@ build {
"source.amazon-ebs.pmm2"
]
provisioner "ansible" {
extra_arguments = [
"--extra-vars",
"pmm_server_image_name=${var.pmm_server_image_name}"
]
playbook_file = "./packer/ansible/pmm2.yml"
}
}