aws_scripts 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +31 -0
- data/.gitignore +11 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +10 -0
- data/aws_scripts.gemspec +42 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/aws_scripts/railtie.rb +9 -0
- data/lib/aws_scripts/version.rb +3 -0
- data/lib/aws_scripts.rb +8 -0
- data/lib/tasks/aws_scripts_tasks.rake +13 -0
- data/scripts/aws/ec/redis/replication-group/create +24 -0
- data/scripts/aws/ec/redis/replication-group/delete +7 -0
- data/scripts/aws/ec/redis/replication-group/describe +9 -0
- data/scripts/aws/ec/redis/replication-group/status +9 -0
- data/scripts/aws/ecr/login +16 -0
- data/scripts/aws/ecr/publish +24 -0
- data/scripts/aws/eks/associate-iam-provider +15 -0
- data/scripts/aws/eks/cluster/create +21 -0
- data/scripts/aws/eks/cluster/delete +14 -0
- data/scripts/aws/eks/install-dependencies +8 -0
- data/scripts/aws/eks/setup-secrets +9 -0
- data/scripts/aws/iam/create-policy +12 -0
- data/scripts/aws/iam/create-service-account +18 -0
- data/scripts/aws/rds/get-endpoint +8 -0
- data/scripts/aws/rds/instance/create +16 -0
- data/scripts/aws/rds/instance/delete +8 -0
- data/scripts/aws/rds/instance/describe +9 -0
- data/scripts/aws/rds/instance/status +9 -0
- data/scripts/aws/utils +29 -0
- data/scripts/runners/create-eks-cluster +31 -0
- data/scripts/runners/create-rds-instance +71 -0
- data/scripts/runners/create-redis-instance +71 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f86517819794a07ab2fd4679007e208f1c119a9fb4ae7dffec5e76ab4d2320dd
|
4
|
+
data.tar.gz: 7e3596fd1b307b15dd3f21ee5a9f717378cda20010a1fcd63345810334f7f740
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1fbaf5ed21a68c85dbac397f44c2bbd2e805ff41d741f21346c1a8200f363d268e5bfc677f558e6977f0800f5cc92bb0b470188221bf131afcfb572140d34c25
|
7
|
+
data.tar.gz: be911aa4d18ee428e69ef4aca81e4cf8795ce324a91b2998845666ed7f31526a015fa9d0a0fc7f3f094095ec65ca212270ef1d112c4660d4ba1a69bbeea4a7ea
|
data/.env.example
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Redis
|
2
|
+
AWS_REPLICATION_GROUP_ID=""
|
3
|
+
AWS_REPLICATION_GROUP_DESCRIPTION=""
|
4
|
+
AWS_REPLICATION_CACHE_NODE_TYPE=""
|
5
|
+
AWS_REPLICATION_ENGINE=""
|
6
|
+
AWS_REPLICATION_CACHE_PARAMETER_GROUP_NAME=""
|
7
|
+
AWS_REPLICATION_CACHE_NUMBER_OF_CLUSTERS=""
|
8
|
+
|
9
|
+
# Database
|
10
|
+
AWS_DB_INSTANCE_ID=""
|
11
|
+
AWS_DB_INSTANCE_CLASS=""
|
12
|
+
AWS_DB_INSTANCE_ENGINE=""
|
13
|
+
AWS_DB_ALLOCATED_STORAGE=""
|
14
|
+
AWS_DB_MASTER_USERNAME=""
|
15
|
+
AWS_DB_MASTER_PASSWORD=""
|
16
|
+
AWS_DB_RETENTION_PERIOD=""
|
17
|
+
|
18
|
+
# EKS
|
19
|
+
EKS_CLUSTER_NAME=""
|
20
|
+
EKS_CLUSTER_VERSION=""
|
21
|
+
EKS_NODE_GROUP_NAME=""
|
22
|
+
EKS_NODE_TYPE=""
|
23
|
+
EKS_NODE_COUNT=""
|
24
|
+
EKS_ZONES=""
|
25
|
+
|
26
|
+
# Policies
|
27
|
+
POLICY_ARN=""
|
28
|
+
POLICY_NAME=""
|
29
|
+
|
30
|
+
# IAM
|
31
|
+
IAM_SERVICE_ACCOUNT=""
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.5
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alvin.crespo@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Alvin Crespo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# AWS Scripts
|
2
|
+
|
3
|
+
This gem provides some low level scripts for managing AWS resources.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'aws_scripts'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install aws_scripts
|
20
|
+
|
21
|
+
Then run the copy scripts task:
|
22
|
+
|
23
|
+
$ rails aws_scripts:copy_scripts
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Check out the wiki for usage information.
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
+
|
33
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jardim-io/aws_scripts. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
42
|
+
|
43
|
+
## Code of Conduct
|
44
|
+
|
45
|
+
Everyone interacting in the AwsScripts project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jardim-io/aws_scripts/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/aws_scripts.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "aws_scripts/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aws_scripts"
|
8
|
+
spec.version = AwsScripts::VERSION
|
9
|
+
spec.authors = ["Alvin Crespo"]
|
10
|
+
spec.email = ["alvin.crespo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Installs useful scripts to manage your AWS resources.}
|
13
|
+
spec.description = %q{This gem installs scripts that make it easy for devs to manage AWS resources within a Ruby on Rails applicaiton.}
|
14
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
24
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
42
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "aws_scripts"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/aws_scripts.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :aws_scripts do
|
2
|
+
desc "Copies AWS scripts to bin directory"
|
3
|
+
task copy_scripts: :environment do
|
4
|
+
source = File.expand_path("../../../scripts", __FILE__)
|
5
|
+
destination = Rails.root.join("bin")
|
6
|
+
|
7
|
+
FileUtils.mkdir_p(destination)
|
8
|
+
|
9
|
+
FileUtils.cp_r("#{source}/.", destination)
|
10
|
+
|
11
|
+
puts "Copied AWS scripts to #{destination}"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# Create replication group. This command will create a replication group with
|
4
|
+
# the below parameters. These parameters are environment variables that are
|
5
|
+
# loaded from the local .env file.
|
6
|
+
#
|
7
|
+
# Congigurable parameters:
|
8
|
+
# - REPLICATION_GROUP_ID
|
9
|
+
# - REPLICATION_GROUP_DESCRIPTION
|
10
|
+
# - REPLICATION_CACHE_NODE_TYPE
|
11
|
+
# - REPLICATION_ENGINE
|
12
|
+
# - REPLICATION_CACHE_PARAMETER_GROUP_NAME
|
13
|
+
# - REPLICATION_CACHE_NUMBER_OF_CLUSTERS
|
14
|
+
|
15
|
+
. .env
|
16
|
+
|
17
|
+
aws elasticache create-replication-group \
|
18
|
+
--replication-group-id "$AWS_REPLICATION_GROUP_ID" \
|
19
|
+
--replication-group-description "$AWS_REPLICATION_GROUP_DESCRIPTION" \
|
20
|
+
--cache-node-type "$AWS_REPLICATION_CACHE_NODE_TYPE" \
|
21
|
+
--engine "$AWS_REPLICATION_ENGINE" \
|
22
|
+
--cache-parameter-group-name "$AWS_REPLICATION_CACHE_PARAMETER_GROUP_NAME" \
|
23
|
+
--num-cache-clusters "$AWS_REPLICATION_CACHE_NUMBER_OF_CLUSTERS" \
|
24
|
+
--no-cli-pager
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -o pipefail
|
5
|
+
|
6
|
+
. ./bin/aws/utils
|
7
|
+
|
8
|
+
check_aws_cli_installed
|
9
|
+
check_docker_installed
|
10
|
+
|
11
|
+
. .env
|
12
|
+
|
13
|
+
user=AWS
|
14
|
+
password=$(aws ecr get-login-password --region "$AWS_REGION")
|
15
|
+
|
16
|
+
docker login -u "$user" -p "$password" "$ECR_HOST"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -o pipefail
|
5
|
+
|
6
|
+
. ./bin/aws/utils
|
7
|
+
|
8
|
+
check_docker_installed
|
9
|
+
|
10
|
+
args=()
|
11
|
+
|
12
|
+
while test $# -gt 0; do
|
13
|
+
case $1 in
|
14
|
+
--tag) tag=$2; shift;;
|
15
|
+
*) args+=("$1");;
|
16
|
+
esac
|
17
|
+
shift
|
18
|
+
done
|
19
|
+
|
20
|
+
set -- "${args[@]}"
|
21
|
+
|
22
|
+
. .env
|
23
|
+
|
24
|
+
docker push "$ECR_URI":"$tag"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -o pipefail
|
5
|
+
|
6
|
+
. ./bin/aws/utils
|
7
|
+
|
8
|
+
check_eksctl_installed
|
9
|
+
|
10
|
+
. .env
|
11
|
+
|
12
|
+
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI
|
13
|
+
|
14
|
+
AWS_PROFILE=eksadmin eksctl create cluster \
|
15
|
+
--name "$EKS_CLUSTER_NAME" \
|
16
|
+
--version "$EKS_CLUSTER_VERSION" \
|
17
|
+
--region "$AWS_REGION" \
|
18
|
+
--nodegroup-name "$EKS_NODE_GROUP_NAME" \
|
19
|
+
--node-type "$EKS_NODE_TYPE" \
|
20
|
+
--nodes "$EKS_NODE_COUNT" \
|
21
|
+
--zones "$EKS_ZONES"
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
. .env
|
4
|
+
|
5
|
+
helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts
|
6
|
+
helm install csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver --namespace kube-system
|
7
|
+
|
8
|
+
kubectl apply -f https://raw.githubusercontent.com/aws/secrets-store-csi-driver-provider-aws/main/deployment/aws-provider-installer.yaml
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
. .env
|
4
|
+
|
5
|
+
aws --region us-east-1 --query Policy.Arn --output text iam create-policy --policy-name $POLICY_NAME --policy-document '{
|
6
|
+
"Version": "2012-10-17",
|
7
|
+
"Statement": [ {
|
8
|
+
"Effect": "Allow",
|
9
|
+
"Action": ["secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret"],
|
10
|
+
"Resource": ["arn:*:secretsmanager:*:*:secret:JardimSecret-??????"]
|
11
|
+
} ]
|
12
|
+
}'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -o pipefail
|
5
|
+
|
6
|
+
. ./bin/aws/utils
|
7
|
+
|
8
|
+
check_eksctl_installed
|
9
|
+
|
10
|
+
. .env
|
11
|
+
|
12
|
+
AWS_PROFILE=eksadmin eksctl create iamserviceaccount \
|
13
|
+
--name "$IAM_SERVICE_ACCOUNT" \
|
14
|
+
--region "$AWS_REGION" \
|
15
|
+
--cluster "$EKS_CLUSTER_NAME" \
|
16
|
+
--attach-policy-arn "$POLICY_ARN" \
|
17
|
+
--approve \
|
18
|
+
--override-existing-serviceaccounts
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
. .env
|
4
|
+
|
5
|
+
echo "[AWS] [RDS] Creating instance $AWS_DB_INSTANCE_ID..."
|
6
|
+
|
7
|
+
aws rds create-db-instance \
|
8
|
+
--db-instance-identifier "$AWS_DB_INSTANCE_ID" \
|
9
|
+
--db-instance-class "$AWS_DB_INSTANCE_CLASS" \
|
10
|
+
--engine "$AWS_DB_INSTANCE_ENGINE" \
|
11
|
+
--allocated-storage "$AWS_DB_ALLOCATED_STORAGE" \
|
12
|
+
--master-username "$AWS_DB_MASTER_USERNAME" \
|
13
|
+
--master-user-password "$AWS_DB_MASTER_PASSWORD" \
|
14
|
+
--backup-retention-period "$AWS_DB_RETENTION_PERIOD" \
|
15
|
+
--region "$AWS_REGION" \
|
16
|
+
--no-cli-pager
|
data/scripts/aws/utils
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
function check_aws_cli_installed {
|
4
|
+
if ! command -v aws &> /dev/null; then
|
5
|
+
echo "AWS CLI is not installed. Please install it first. https://aws.amazon.com/cli/"
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
}
|
9
|
+
|
10
|
+
function check_helm_installed {
|
11
|
+
if ! command -v helm &> /dev/null; then
|
12
|
+
echo "hl could not be found. Please install it first. https://helm.sh/"
|
13
|
+
exit 1
|
14
|
+
fi
|
15
|
+
}
|
16
|
+
|
17
|
+
function check_eksctl_installed {
|
18
|
+
if ! command -v eksctl &> /dev/null; then
|
19
|
+
echo "eksctl could not be found. Please install it first. https://eksctl.io/"
|
20
|
+
exit 1
|
21
|
+
fi
|
22
|
+
}
|
23
|
+
|
24
|
+
function check_docker_installed {
|
25
|
+
if ! command -v docker &> /dev/null; then
|
26
|
+
echo "Docker could not be found. Please install it first. https://www.docker.com/"
|
27
|
+
exit 1
|
28
|
+
fi
|
29
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -o pipefail
|
5
|
+
|
6
|
+
. ./bin/aws/utils
|
7
|
+
|
8
|
+
check_aws_cli_installed
|
9
|
+
check_helm_installed
|
10
|
+
|
11
|
+
# Function to clean up resources in case of failure
|
12
|
+
cleanup() {
|
13
|
+
echo "[UTILS] [EKS] An error occurred."
|
14
|
+
}
|
15
|
+
|
16
|
+
# Trap any error, and call our cleanup function
|
17
|
+
trap cleanup ERR
|
18
|
+
|
19
|
+
# Source .env file
|
20
|
+
. .env
|
21
|
+
|
22
|
+
# 1. Create cluster
|
23
|
+
./bin/aws/eks/cluster/create
|
24
|
+
|
25
|
+
# 2. Setup secrets
|
26
|
+
./bin/aws/eks/setup-secrets
|
27
|
+
|
28
|
+
# 3. Apply deployments
|
29
|
+
# kubectl apply -f deployment/secrets.yml
|
30
|
+
# kubectl apply -f deployment/sidekiq.yml
|
31
|
+
# kubectl apply -f deployment/app.yml
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -o pipefail
|
5
|
+
|
6
|
+
. ./bin/aws/utils
|
7
|
+
|
8
|
+
check_aws_cli_installed
|
9
|
+
|
10
|
+
# Function to clean up resources in case of failure
|
11
|
+
cleanup() {
|
12
|
+
echo "[UTILS] [RDS] An error occurred. Deleting RDS instance..."
|
13
|
+
./bin/aws/rds/instance/delete
|
14
|
+
}
|
15
|
+
|
16
|
+
# Trap any error, and call our cleanup function
|
17
|
+
trap cleanup ERR
|
18
|
+
|
19
|
+
# Source .env file
|
20
|
+
. .env
|
21
|
+
|
22
|
+
# ----------------------------------------------------------------------------
|
23
|
+
# Create RDS instance
|
24
|
+
# ----------------------------------------------------------------------------
|
25
|
+
|
26
|
+
echo "[UTILS] [RDS] Running RDS creation script for $DB_INSTANCE_ID..."
|
27
|
+
|
28
|
+
./bin/aws/rds/instance/create
|
29
|
+
|
30
|
+
# ----------------------------------------------------------------------------
|
31
|
+
# Wait for RDS instance to be available
|
32
|
+
# ----------------------------------------------------------------------------
|
33
|
+
|
34
|
+
DB_STATUS=""
|
35
|
+
|
36
|
+
while [ "$DB_STATUS" != "available" ]; do
|
37
|
+
echo "[UTILS] [RDS] Waiting for RDS instance to be available..."
|
38
|
+
|
39
|
+
DB_STATUS=$(bin/aws/rds/instance/status)
|
40
|
+
|
41
|
+
sleep 10
|
42
|
+
done
|
43
|
+
|
44
|
+
echo "[UTILS] [RDS] The RDS instance is available."
|
45
|
+
|
46
|
+
DB_ARN=$(./bin/aws/rds/instance/describe)
|
47
|
+
|
48
|
+
echo "[UTILS] [RDS] The ARN of the RDS instance is: $DB_ARN"
|
49
|
+
|
50
|
+
# ----------------------------------------------------------------------------
|
51
|
+
# Update .env file with RDS instance ARN
|
52
|
+
# ----------------------------------------------------------------------------
|
53
|
+
|
54
|
+
ENV_FILE=".env"
|
55
|
+
KEY_TO_REPLACE="DB_ARN"
|
56
|
+
|
57
|
+
# Check if key exists in .env file
|
58
|
+
if grep -q "$KEY_TO_REPLACE" $ENV_FILE; then
|
59
|
+
# Key found, so update it
|
60
|
+
echo "[UTILS] [RDS] Updating .env file with RDS instance ARN..."
|
61
|
+
sed -i '.bak' "s/^$KEY_TO_REPLACE=.*/$KEY_TO_REPLACE=$DB_ARN/" $ENV_FILE
|
62
|
+
else
|
63
|
+
# Key not found, so append it
|
64
|
+
echo "[UTILS] [RDS] Appending .env file with RDS instance ARN..."
|
65
|
+
echo "$KEY_TO_REPLACE=$DB_ARN" >> $ENV_FILE
|
66
|
+
fi
|
67
|
+
|
68
|
+
echo "[UTILS] [RDS] Updated .env file with RDS instance ARN: $DB_ARN"
|
69
|
+
|
70
|
+
# Remove the trap since everything was successful
|
71
|
+
trap - ERR
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -o pipefail
|
5
|
+
|
6
|
+
. ./bin/aws/utils
|
7
|
+
|
8
|
+
check_aws_cli_installed
|
9
|
+
|
10
|
+
# Function to clean up resources in case of failure
|
11
|
+
cleanup() {
|
12
|
+
echo "[UTILS] [REDIS] An error occurred. Deleting RDS instance..."
|
13
|
+
./bin/aws/ec/redis/replication-group/delete
|
14
|
+
}
|
15
|
+
|
16
|
+
# Trap any error, and call our cleanup function
|
17
|
+
trap cleanup ERR
|
18
|
+
|
19
|
+
# Source .env file
|
20
|
+
. .env
|
21
|
+
|
22
|
+
# ----------------------------------------------------------------------------
|
23
|
+
# Create RDS instance
|
24
|
+
# ----------------------------------------------------------------------------
|
25
|
+
|
26
|
+
echo "[UTILS] [REDIS] Running Redis creation script for $REPLICATION_GROUP_ID..."
|
27
|
+
|
28
|
+
./bin/aws/ec/redis/replication-group/create
|
29
|
+
|
30
|
+
# ----------------------------------------------------------------------------
|
31
|
+
# Wait for Redis instance to be available
|
32
|
+
# ----------------------------------------------------------------------------
|
33
|
+
|
34
|
+
REPLICATION_GROUP_STATUS=""
|
35
|
+
|
36
|
+
while [ "$REPLICATION_GROUP_STATUS" != "available" ]; do
|
37
|
+
echo "[UTILS] [REDIS] Waiting for Redis instance to be available..."
|
38
|
+
|
39
|
+
REPLICATION_GROUP_STATUS=$(./bin/aws/ec/redis/replication-group/status)
|
40
|
+
|
41
|
+
sleep 10
|
42
|
+
done
|
43
|
+
|
44
|
+
echo "[UTILS] [REDIS] The Redis instance is available."
|
45
|
+
|
46
|
+
REPLICATION_GROUP_ADDRESS=$(./bin/aws/ec/redis/replication-group/describe)
|
47
|
+
|
48
|
+
echo "[UTILS] [REDIS] The Address of the Redis instance is: $REPLICATION_GROUP_ADDRESS"
|
49
|
+
|
50
|
+
# ----------------------------------------------------------------------------
|
51
|
+
# Update .env file with RDS instance ARN
|
52
|
+
# ----------------------------------------------------------------------------
|
53
|
+
|
54
|
+
ENV_FILE=".env"
|
55
|
+
KEY_TO_REPLACE="REPLICATION_GROUP_ADDRESS"
|
56
|
+
|
57
|
+
# Check if key exists in .env file
|
58
|
+
if grep -q "$KEY_TO_REPLACE" $ENV_FILE; then
|
59
|
+
# Key found, so update it
|
60
|
+
echo "[UTILS] [REDIS] Updating .env file with RDS instance ARN..."
|
61
|
+
sed -i '.bak' "s/^$KEY_TO_REPLACE=.*/$KEY_TO_REPLACE=$REPLICATION_GROUP_ADDRESS/" $ENV_FILE
|
62
|
+
else
|
63
|
+
# Key not found, so append it
|
64
|
+
echo "[UTILS] [REDIS] Appending .env file with RDS instance ARN..."
|
65
|
+
echo "$KEY_TO_REPLACE=$REPLICATION_GROUP_ADDRESS" >> $ENV_FILE
|
66
|
+
fi
|
67
|
+
|
68
|
+
echo "[UTILS] [REDIS] Updated .env file with Redis address: $REPLICATION_GROUP_ADDRESS"
|
69
|
+
|
70
|
+
# Remove the trap since everything was successful
|
71
|
+
trap - ERR
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_scripts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alvin Crespo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: This gem installs scripts that make it easy for devs to manage AWS resources
|
56
|
+
within a Ruby on Rails applicaiton.
|
57
|
+
email:
|
58
|
+
- alvin.crespo@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".env.example"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".ruby-version"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- aws_scripts.gemspec
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- lib/aws_scripts.rb
|
76
|
+
- lib/aws_scripts/railtie.rb
|
77
|
+
- lib/aws_scripts/version.rb
|
78
|
+
- lib/tasks/aws_scripts_tasks.rake
|
79
|
+
- scripts/aws/ec/redis/replication-group/create
|
80
|
+
- scripts/aws/ec/redis/replication-group/delete
|
81
|
+
- scripts/aws/ec/redis/replication-group/describe
|
82
|
+
- scripts/aws/ec/redis/replication-group/status
|
83
|
+
- scripts/aws/ecr/login
|
84
|
+
- scripts/aws/ecr/publish
|
85
|
+
- scripts/aws/eks/associate-iam-provider
|
86
|
+
- scripts/aws/eks/cluster/create
|
87
|
+
- scripts/aws/eks/cluster/delete
|
88
|
+
- scripts/aws/eks/install-dependencies
|
89
|
+
- scripts/aws/eks/setup-secrets
|
90
|
+
- scripts/aws/iam/create-policy
|
91
|
+
- scripts/aws/iam/create-service-account
|
92
|
+
- scripts/aws/rds/get-endpoint
|
93
|
+
- scripts/aws/rds/instance/create
|
94
|
+
- scripts/aws/rds/instance/delete
|
95
|
+
- scripts/aws/rds/instance/describe
|
96
|
+
- scripts/aws/rds/instance/status
|
97
|
+
- scripts/aws/utils
|
98
|
+
- scripts/runners/create-eks-cluster
|
99
|
+
- scripts/runners/create-rds-instance
|
100
|
+
- scripts/runners/create-redis-instance
|
101
|
+
homepage:
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubygems_version: 3.2.33
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Installs useful scripts to manage your AWS resources.
|
124
|
+
test_files: []
|