Skip to content

Commit

Permalink
update docker
Browse files Browse the repository at this point in the history
  • Loading branch information
POPPIN-FUMI committed Sep 15, 2022
1 parent ec349c8 commit da2af97
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 44 deletions.
2 changes: 2 additions & 0 deletions apps/api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
dump.rdb
13 changes: 8 additions & 5 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
FROM ruby:3.1.2

RUN apt-get update -qq && apt-get install -y nodejs redis-server libcurl3-dev
FROM ruby:3.1.2-slim-buster

RUN apt-get update -qq && apt-get install -y redis-server libcurl3-dev
RUN apt update && apt install -y \
build-essential libpq-dev \
&& rm -rf /var/lib/apt/lists/*

USER root

RUN mkdir /myapp
WORKDIR /myapp

COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN gem install bundler:2.3.21
RUN bundle
RUN gem install bundler:2.3.22
RUN bundle --without development test
COPY . /myapp

CMD ["foreman", "start"]
36 changes: 18 additions & 18 deletions apps/api/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ PROJECT_ID = SOULs.configuration.project_id
REGION = SOULs.configuration.region
GCR_REGION = SOULs.configuration.gcr_region
INATANCE_NAME = SOULs.configuration.instance_name
DB_USER = ENV.fetch("DB_USER", nil)
DB_HOST = "/cloudsql/#{PROJECT_ID}:#{REGION}:#{INATANCE_NAME}"
DB_NAME = ENV.fetch("DB_NAME", nil)
DB_PW = ENV.fetch("DB_PW", nil)
SECRET_KEY_BASE = ENV.fetch("SECRET_KEY_BASE", nil)
PORT = ENV["PORT"] || 4000
DB_USER = ENV.fetch("SOULS_DB_USER", nil)
DB_HOST = "/cloudsql/#{PROJECT_ID}:#{REGION}:#{INATANCE_NAME}".freeze
DB_NAME = ENV.fetch("SOULS_DB_NAME", nil)
DB_PW = ENV.fetch("SOULS_DB_PW", nil)
SECRET_KEY_BASE = ENV.fetch("SOULS_SECRET_KEY_BASE", nil)
TZ = ENV.fetch("TZ", nil)

task :build do
system "docker build . -t #{APP_NAME}"
end

task :run do
system "docker run -d --env-file .env -p #{PORT}:#{PORT} --restart always --name #{APP_NAME} #{APP_NAME}"
system "docker run --env-file .env -p #{PORT}:#{PORT} --restart always --name #{APP_NAME} #{APP_NAME}"
end

task :rm do
Expand Down Expand Up @@ -55,24 +55,24 @@ rescue StandardError => e
end

task :run_deploy do
system "gcloud beta run deploy #{APP_NAME_H} \
--image #{GCR_REGION}/#{PROJECT_ID}/#{APP_NAME}:latest \
system "gcloud run deploy souls-#{APP_NAME_H}-api \
--service-account=#{APP_NAME}@#{PROJECT_ID}.iam.gserviceaccount.com \
--image=#{GCR_REGION}/#{PROJECT_ID}/#{APP_NAME}:latest \
--memory=4Gi \
--cpu=2 \
--quiet \
--region=#{REGION} \
--project=#{PROJECT_ID} \
--allow-unauthenticated \
--platform=managed \
--no-cpu-throttling \
--execution-environment=gen2 \
--set-cloudsql-instances=#{PROJECT_ID}:#{REGION}:#{INATANCE_NAME} \
--port=8080 \
--set-env-vars='DB_USER=#{DB_USER}' \
--set-env-vars='DB_HOST=#{DB_HOST}' \
--set-env-vars='DB_NAME=#{DB_NAME}' \
--set-env-vars='DB_PW=#{DB_PW}' \
--set-env-vars='RACK_ENV=production' \
--set-env-vars='SECRET_KEY_BASE=#{SECRET_KEY_BASE}' \
--set-env-vars='RUBY_YJIT_ENABLE=1' \
--project #{PROJECT_ID}"
--set-env-vars='SOULS_DB_USER=#{DB_USER}' \
--set-env-vars='SOULS_DB_PW=#{DB_PW}' \
--set-env-vars='SOULS_DB_HOST=#{DB_HOST}' \
--set-env-vars='TZ=#{TZ}' \
--set-env-vars='SOULS_SECRET_KEY_BASE='#{SECRET_KEY_BASE}'' \
--set-env-vars='SOULS_GCP_PROJECT_ID=#{PROJECT_ID}' \
--set-env-vars='RUBY_YJIT_ENABLE=1'"
end
2 changes: 0 additions & 2 deletions apps/api/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
require "rack/contrib"
require "active_support"
require "active_support/core_ext"
require "factory_bot"
require "faker"
require "logger"
require "base64"
require "search_object"
Expand Down
10 changes: 6 additions & 4 deletions apps/api/config.ru
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require "./app"
require "rack/cors"
require "graphql_playground"
if ENV["RACK_ENV"] == "development"
require "graphql_playground"

map "/playground" do
endpoint = SOULs.configuration.endpoint
use GraphQLPlayground, endpoint:
map "/playground" do
endpoint = SOULs.configuration.endpoint
use GraphQLPlayground, endpoint:
end
end

run SOULsApi
Expand Down
2 changes: 2 additions & 0 deletions apps/worker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
dump.rdb
22 changes: 7 additions & 15 deletions apps/worker/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ APP_NAME_H = APP_NAME.gsub("_", "-")
PROJECT_ID = SOULs.configuration.project_id
REGION = SOULs.configuration.region
GCR_REGION = SOULs.configuration.gcr_region
PORT = ENV["PORT"] || 4000

task :build do
system "docker build . -t #{APP_NAME}"
end

task :run do
system "docker run -d --env-file .env -p #{PORT}:#{PORT} --restart always --name #{APP_NAME} #{APP_NAME}"
system "docker run --env-file .env -p #{PORT}:#{PORT} --restart always --name #{APP_NAME} #{APP_NAME}"
end

task :rm do
Expand All @@ -25,7 +24,6 @@ end
task :push do
system "docker push #{GCR_REGION}/#{PROJECT_ID}/#{APP_NAME}:latest"
end

task :deploy do
rubocop_test = system("bundle exec rubocop")
raise(StandardError, "rubocop failed!") unless rubocop_test
Expand All @@ -46,24 +44,18 @@ rescue StandardError => e
end

task :run_deploy do
system "gcloud beta run deploy #{APP_NAME_H} \
--image #{GCR_REGION}/#{PROJECT_ID}/#{APP_NAME}:latest \
system "gcloud run deploy souls-#{APP_NAME_H}-api \
--service-account=#{APP_NAME}@#{PROJECT_ID}.iam.gserviceaccount.com \
--image=#{GCR_REGION}/#{PROJECT_ID}/#{APP_NAME}:latest \
--memory=4Gi \
--cpu=2 \
--quiet \
--region=#{REGION} \
--project=#{PROJECT_ID} \
--allow-unauthenticated \
--platform=managed \
--no-cpu-throttling \
--execution-environment=gen2 \
--set-cloudsql-instances=#{PROJECT_ID}:#{REGION}:#{INATANCE_NAME} \
--port=8080 \
--set-env-vars='DB_USER=#{DB_USER}' \
--set-env-vars='DB_HOST=#{DB_HOST}' \
--set-env-vars='DB_NAME=#{DB_NAME}' \
--set-env-vars='DB_PW=#{DB_PW}' \
--set-env-vars='RACK_ENV=production' \
--set-env-vars='SECRET_KEY_BASE=#{SECRET_KEY_BASE}' \
--set-env-vars='RUBY_YJIT_ENABLE=1' \
--project #{PROJECT_ID}"
--set-env-vars='SOULS_GCP_PROJECT_ID=#{PROJECT_ID}' \
--set-env-vars='RUBY_YJIT_ENABLE=1'"
end

0 comments on commit da2af97

Please sign in to comment.