Last active
April 18, 2021 14:33
-
-
Save themoxman/1d137b9a1729ba8722e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM codeship/ruby | |
MAINTAINER Dave Mox <[email protected]> | |
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | |
git \ | |
vim | |
COPY Makefile /src/ | |
COPY Gemfile* /src/ | |
WORKDIR /src | |
RUN make install | |
COPY . /src | |
CMD ["bin/in_s3_env", "bin/burgundy"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'aws-sdk' | |
# basic S3 client | |
# note: the client will use the instance profile credentials | |
# when this script is called from the ec2 instance | |
s3_client = Aws::S3::Client.new(region: 'us-east-1') | |
# kms client | |
# note: the client will use the instance profile credentials | |
# when this script is called from the ec2 instance | |
kms_client = Aws::KMS::Client.new(region: 'us-east-1') | |
# retrieve cmk key id | |
aliases = kms_client.list_aliases.aliases | |
key = aliases.find { |alias_struct| alias_struct.alias_name == "alias/chime-secrets" } | |
key_id = key.target_key_id | |
# encryption client | |
s3_encryption_client = Aws::S3::Encryption::Client.new( | |
client: s3_client, | |
kms_key_id: key_id, | |
kms_client: kms_client, | |
) | |
# retrieve and decrypt .env from s3 | |
response = s3_encryption_client.get_object(bucket: 'chime-secrets', key: '.env') | |
# build string of env vars to be exported. | |
exports = "" | |
response.body.read.each_line { |line| exports << "export #{line.chomp};" } | |
puts exports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
eval "$(bin/get_s3_env)" | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment