From 65afe063020eeff3066a8c6ee172e628e037a6f7 Mon Sep 17 00:00:00 2001 From: Den85s Date: Thu, 24 Aug 2023 18:26:34 +0300 Subject: [PATCH 1/4] Add new branch packer --- .gitignore | 2 + README.md | 6 +-- README.md~ | 2 +- deploy.sh => config-scripts/deploy.sh | 0 .../install_mongodb.sh | 0 .../install_ruby.sh | 0 packer/files/install_reddit.sh | 12 ++++++ packer/files/puma.service | 13 +++++++ packer/immutable.json | 37 +++++++++++++++++++ packer/scripts/install_mongodb.sh | 17 +++++++++ packer/scripts/install_ruby.sh | 4 ++ packer/ubuntu16.json | 27 ++++++++++++++ packer/variable.json.examples | 5 +++ 13 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 .gitignore rename deploy.sh => config-scripts/deploy.sh (100%) rename install_mongodb.sh => config-scripts/install_mongodb.sh (100%) rename install_ruby.sh => config-scripts/install_ruby.sh (100%) create mode 100644 packer/files/install_reddit.sh create mode 100644 packer/files/puma.service create mode 100644 packer/immutable.json create mode 100755 packer/scripts/install_mongodb.sh create mode 100755 packer/scripts/install_ruby.sh create mode 100644 packer/ubuntu16.json create mode 100644 packer/variable.json.examples diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2fa97cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/packer/variable.json +*~ diff --git a/README.md b/README.md index 1fc7990..01f4e3e 100644 --- a/README.md +++ b/README.md @@ -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 сервером diff --git a/README.md~ b/README.md~ index 284b827..1fc7990 100644 --- a/README.md~ +++ b/README.md~ @@ -1,5 +1,5 @@ # Den85s_infra -testapp_IP = 62.84.118.51 +testapp_IP = 158.160.114.141 testapp_port = 9292 diff --git a/deploy.sh b/config-scripts/deploy.sh similarity index 100% rename from deploy.sh rename to config-scripts/deploy.sh diff --git a/install_mongodb.sh b/config-scripts/install_mongodb.sh similarity index 100% rename from install_mongodb.sh rename to config-scripts/install_mongodb.sh diff --git a/install_ruby.sh b/config-scripts/install_ruby.sh similarity index 100% rename from install_ruby.sh rename to config-scripts/install_ruby.sh diff --git a/packer/files/install_reddit.sh b/packer/files/install_reddit.sh new file mode 100644 index 0000000..56e3ac0 --- /dev/null +++ b/packer/files/install_reddit.sh @@ -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 diff --git a/packer/files/puma.service b/packer/files/puma.service new file mode 100644 index 0000000..fa6605e --- /dev/null +++ b/packer/files/puma.service @@ -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 diff --git a/packer/immutable.json b/packer/immutable.json new file mode 100644 index 0000000..bfdf77e --- /dev/null +++ b/packer/immutable.json @@ -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}}" + } + ] +} diff --git a/packer/scripts/install_mongodb.sh b/packer/scripts/install_mongodb.sh new file mode 100755 index 0000000..7a43854 --- /dev/null +++ b/packer/scripts/install_mongodb.sh @@ -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 diff --git a/packer/scripts/install_ruby.sh b/packer/scripts/install_ruby.sh new file mode 100755 index 0000000..41e492d --- /dev/null +++ b/packer/scripts/install_ruby.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sudo apt update +sudo apt install -y ruby-full bundler build-essential diff --git a/packer/ubuntu16.json b/packer/ubuntu16.json new file mode 100644 index 0000000..5a051db --- /dev/null +++ b/packer/ubuntu16.json @@ -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}}" + } + ] +} diff --git a/packer/variable.json.examples b/packer/variable.json.examples new file mode 100644 index 0000000..bad1d2d --- /dev/null +++ b/packer/variable.json.examples @@ -0,0 +1,5 @@ +{ + "service_account_key_file": "/home/XXX/XXX/key.json", + "folder_id": "XXXXXXXXXXXXXXXXXXXX", + "source_image_family": "ubuntu-1604-lts" + } From 2a31decf787085205acb95f79c9e824f4eee7e7d Mon Sep 17 00:00:00 2001 From: Den85s Date: Thu, 24 Aug 2023 18:28:52 +0300 Subject: [PATCH 2/4] fix file name --- packer/{variable.json.examples => variable.json.example} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packer/{variable.json.examples => variable.json.example} (100%) diff --git a/packer/variable.json.examples b/packer/variable.json.example similarity index 100% rename from packer/variable.json.examples rename to packer/variable.json.example From e06279d9e860e8b23107a4d1ad8180ce46ec4736 Mon Sep 17 00:00:00 2001 From: Den85s Date: Thu, 24 Aug 2023 18:30:49 +0300 Subject: [PATCH 3/4] fix file name --- packer/{variable.json.example => variables.json.example} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packer/{variable.json.example => variables.json.example} (100%) diff --git a/packer/variable.json.example b/packer/variables.json.example similarity index 100% rename from packer/variable.json.example rename to packer/variables.json.example From 2cd48ec77b774c38821b9da392ec68748d217ea7 Mon Sep 17 00:00:00 2001 From: Den85s Date: Thu, 24 Aug 2023 18:37:31 +0300 Subject: [PATCH 4/4] fix file name --- packer/key.json | 8 ++++++++ packer/variables.json.example | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 packer/key.json diff --git a/packer/key.json b/packer/key.json new file mode 100644 index 0000000..efc1289 --- /dev/null +++ b/packer/key.json @@ -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" +} diff --git a/packer/variables.json.example b/packer/variables.json.example index bad1d2d..af10f81 100644 --- a/packer/variables.json.example +++ b/packer/variables.json.example @@ -1,5 +1,5 @@ { - "service_account_key_file": "/home/XXX/XXX/key.json", + "service_account_key_file": "key.json", "folder_id": "XXXXXXXXXXXXXXXXXXXX", "source_image_family": "ubuntu-1604-lts" }