Skip to content

Commit 837a2b0

Browse files
committed
kea: db-upgrade.rb
1 parent 66b10e8 commit 837a2b0

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

kea/Dockerfile

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ RUN --mount=type=cache,dst=/build/stork/tools \
3434

3535
###
3636

37+
FROM $BASE as bundler
38+
RUN apt-get update \
39+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
40+
ruby \
41+
ruby-bundler
42+
COPY Gemfile* /app/
43+
ENV BUNDLE_GEMFILE /app/Gemfile
44+
ENV BUNDLE_PATH /app/vendor/bundle
45+
ENV BUNDLE_DEPLOYMENT 1
46+
ENV BUNDLE_JOBS 16
47+
ENV BUNDLE_WITHOUT development:test
48+
RUN bundle install
49+
50+
###
51+
3752
FROM --platform=$BUILDPLATFORM $BASE as config
3853
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y jsonnet
3954
WORKDIR /app
@@ -50,9 +65,10 @@ VOLUME /run/kea
5065

5166
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt/lists apt-get update \
5267
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
68+
curl \
5369
ca-certificates \
5470
dumb-init \
55-
ruby \
71+
ruby ruby-bundler \
5672
iproute2 \
5773
mysql-client
5874

@@ -70,8 +86,19 @@ RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib
7086

7187
COPY --from=build-healthz /app/bin/healthz /app/healthzd
7288
COPY --from=build-stork /build/go/bin/stork-agent /app/stork-agent
89+
90+
COPY Gemfile* /app/
91+
COPY --from=bundler /app/vendor/bundle /app/vendor/bundle
92+
ENV BUNDLE_GEMFILE /app/Gemfile
93+
ENV BUNDLE_PATH /app/vendor/bundle
94+
ENV BUNDLE_DEPLOYMENT 1
95+
ENV BUNDLE_JOBS 16
96+
ENV BUNDLE_WITHOUT development:test
97+
7398
RUN ln -s /usr/lib/$(uname -m)-linux-gnu/kea/hooks /app/kea-hooks
99+
74100
COPY run.sh /app/run.sh
101+
COPY db-upgrade.rb /app/db-upgrade.rb
75102
COPY choose_dhcp_server_id.rb /app/choose_dhcp_server_id.rb
76103
COPY --from=config /app/kea-ctrl-agent.json /app/kea-ctrl-agent.json
77104

kea/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
gem 'aws-sdk-rds'
3+
gem 'rexml'

kea/Gemfile.lock

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
aws-eventstream (1.3.2)
5+
aws-partitions (1.1065.0)
6+
aws-sdk-core (3.220.1)
7+
aws-eventstream (~> 1, >= 1.3.0)
8+
aws-partitions (~> 1, >= 1.992.0)
9+
aws-sigv4 (~> 1.9)
10+
base64
11+
jmespath (~> 1, >= 1.6.1)
12+
aws-sdk-rds (1.272.0)
13+
aws-sdk-core (~> 3, >= 3.216.0)
14+
aws-sigv4 (~> 1.5)
15+
aws-sigv4 (1.11.0)
16+
aws-eventstream (~> 1, >= 1.0.2)
17+
base64 (0.2.0)
18+
jmespath (1.6.2)
19+
rexml (3.4.1)
20+
21+
PLATFORMS
22+
ruby
23+
24+
DEPENDENCIES
25+
aws-sdk-rds
26+
rexml
27+
28+
BUNDLED WITH
29+
2.6.3

kea/db-upgrade.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env ruby
2+
require 'bundler/setup'
3+
require 'aws-sdk-rds'
4+
require 'open-uri'
5+
require 'resolv'
6+
7+
REGION = ENV.fetch('AWS_REGION')
8+
File.write '/app/rds-ca-bundle.pem', URI.open("https://truststore.pki.rds.amazonaws.com/#{REGION}/#{REGION}-bundle.pem", 'r', &:read)
9+
@auth = Aws::RDS::AuthTokenGenerator.new(credentials: Aws::CredentialProviderChain.new.resolve)
10+
11+
def run(host:, name:)
12+
actual_host = Resolv::DNS.new.getresource(host, Resolv::DNS::Resource::IN::CNAME).name.to_s rescue host
13+
user_name = ENV.fetch('KEA_ADMIN_DB_USER')
14+
token = @auth.generate_auth_token(region: REGION, endpoint: "#{actual_host}:3306", expires_in: 900, user_name: user_name)
15+
ENV['KEA_ADMIN_DB_PASSWORD'] = token
16+
puts ">>>> kea-admin db-upgrade mysql -n #{name} -h #{actual_host}"
17+
system(
18+
*%w(kea-admin db-upgrade mysql),
19+
'-h', actual_host,
20+
'-u', user_name,
21+
'-n', name,
22+
'-x', "--enable-cleartext-plugin --ssl-ca /app/rds-ca-bundle.pem",
23+
exception: true
24+
)
25+
end
26+
27+
run(host: ENV.fetch('LEASE_DATABASE_HOST'), name: ENV.fetch('LEASE_DATABASE_NAME'))
28+
run(host: ENV.fetch('HOSTS_DATABASE_HOST'), name: ENV.fetch('HOSTS_DATABASE_NAME'))

0 commit comments

Comments
 (0)