Skip to content

Commit

Permalink
Merge pull request #4 from Otus-DevOps-2023-05/packer-base
Browse files Browse the repository at this point in the history
Packer base
  • Loading branch information
Den85s authored Aug 30, 2023
2 parents 888c00d + 2cd48ec commit 222984e
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/packer/variable.json
*~
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Den85s_infra


testapp_IP = 158.160.114.141
testapp_port = 9292
установлен Packer
создан шаблон ubuntu16.json для создания baked-образа
создан шаблон immutable.json.json для создания bake-образа c запущенным http сервером
2 changes: 1 addition & 1 deletion README.md~
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Den85s_infra


testapp_IP = 62.84.118.51
testapp_IP = 158.160.114.141
testapp_port = 9292
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions packer/files/install_reddit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

sudo apt-get update
sudo apt-get install -y git
git clone -b monolith https://github.com/express42/reddit.git
cd reddit && bundle install
# puma -d
sudo mv /tmp/puma.service /etc/systemd/system/puma.service

sudo systemctl start puma

sudo systemctl enable puma
13 changes: 13 additions & 0 deletions packer/files/puma.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=puma
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/reddit
ExecStart=/bin/bash -lc 'puma'
Restart=always

[Install]
WantedBy=multi-user.target
37 changes: 37 additions & 0 deletions packer/immutable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"builders": [
{
"type": "yandex",
"service_account_key_file": "{{user `service_account_key_file`}}",
"folder_id": "{{user `folder_id`}}",
"source_image_family": "{{user `source_image_family`}}",
"image_name": "reddit-base-{{timestamp}}",
"image_family": "reddit-full",
"ssh_username": "ubuntu",
"platform_id": "standard-v1",
"use_ipv4_nat": "true"
}
],
"provisioners": [
{
"type": "shell",
"script": "scripts/install_ruby.sh",
"execute_command": "sudo {{.Path}}"
},
{
"type": "shell",
"script": "scripts/install_mongodb.sh",
"execute_command": "sudo {{.Path}}"
},
{
"type": "file",
"source": "files/puma.service",
"destination": "/tmp/puma.service"
},
{
"type": "shell",
"script": "files/install_reddit.sh",
"execute_command": "sudo {{.Path}}"
}
]
}
8 changes: 8 additions & 0 deletions packer/key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "ajeXXXXXXXXXX8c",
"service_account_id": "ajXXXXXXXXXXmrm",
"created_at": "2023-08-16T17:54:47.800670721Z",
"key_algorithm": "RSA_2048",
"public_key": "-----BEGIN PUBLIC KEY-----\nMIIoHfu/Z25UbMjXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+\nJQIDAQAB\n-----END PUBLIC KEY-----\n",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXgIz4RUTvMKJBts=\n-----END PRIVATE KEY-----\n"
}
17 changes: 17 additions & 0 deletions packer/scripts/install_mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

sudo apt-get update

sudo apt-get install -y mongodb-org

sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
4 changes: 4 additions & 0 deletions packer/scripts/install_ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

sudo apt update
sudo apt install -y ruby-full bundler build-essential
27 changes: 27 additions & 0 deletions packer/ubuntu16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"builders": [
{
"type": "yandex",
"service_account_key_file": "{{user `service_account_key_file`}}",
"folder_id": "{{user `folder_id`}}",
"source_image_family": "{{user `source_image_family`}}",
"image_name": "reddit-base-{{timestamp}}",
"image_family": "reddit-base",
"ssh_username": "ubuntu",
"platform_id": "standard-v1",
"use_ipv4_nat": "true"
}
],
"provisioners": [
{
"type": "shell",
"script": "scripts/install_ruby.sh",
"execute_command": "sudo {{.Path}}"
},
{
"type": "shell",
"script": "scripts/install_mongodb.sh",
"execute_command": "sudo {{.Path}}"
}
]
}
5 changes: 5 additions & 0 deletions packer/variables.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"service_account_key_file": "key.json",
"folder_id": "XXXXXXXXXXXXXXXXXXXX",
"source_image_family": "ubuntu-1604-lts"
}

0 comments on commit 222984e

Please sign in to comment.