Set up for internal deployment
This commit is contained in:
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env ruby
|
||||
require "bundler/inline"
|
||||
require "yaml"
|
||||
|
||||
gemfile do
|
||||
source "https://rubygems.org"
|
||||
gem "base64"
|
||||
gem "bcrypt_pbkdf"
|
||||
gem "ed25519"
|
||||
gem "sshkit"
|
||||
end
|
||||
|
||||
include SSHKit::DSL
|
||||
|
||||
config_variant = "-#{ARGV[0]}" if ARGV[0]
|
||||
config = YAML.load_file("config/deploy#{config_variant}.yml")
|
||||
|
||||
HOSTS = [ config["host"] ]
|
||||
REMOTE_USER = config["ssh_user"]
|
||||
DOCKER_IMAGE_NAME = config["image"]
|
||||
ARCH = config["arch"] || `arch`.strip
|
||||
GIT_SHA = `git rev-parse HEAD`.strip
|
||||
DOCKER_TAGGED_IMAGE_NAME = [ DOCKER_IMAGE_NAME, GIT_SHA ].join(":")
|
||||
PORTS = [ "80:80", "443:443" ]
|
||||
ENVS = { TLS_DOMAIN: config["ssl_domain"] }
|
||||
ENV_FILE = ".fizzy-env"
|
||||
|
||||
SSHKit::Backend::Netssh.configure do |ssh|
|
||||
ssh.connection_timeout = 30
|
||||
ssh.ssh_options = { user: REMOTE_USER }
|
||||
end
|
||||
|
||||
def announcing(message)
|
||||
puts "\n\e[1;36m#{message}\e[0m"
|
||||
yield
|
||||
end
|
||||
|
||||
announcing "Building and pushing image..." do
|
||||
versioning = "--build-arg APP_VERSION=#{GIT_SHA[...6]} --build-arg GIT_REVISION=#{GIT_SHA}"
|
||||
|
||||
on(:local) do
|
||||
execute :docker, :build, "-t", DOCKER_TAGGED_IMAGE_NAME, versioning, "--platform", ARCH, "."
|
||||
execute :docker, :push, DOCKER_TAGGED_IMAGE_NAME
|
||||
end
|
||||
end
|
||||
|
||||
announcing "Pulling image on remote..." do
|
||||
on(HOSTS) do
|
||||
execute :docker, :pull, DOCKER_TAGGED_IMAGE_NAME
|
||||
end
|
||||
end
|
||||
|
||||
announcing "Start container on remote..." do
|
||||
restart_policy = "--restart unless-stopped"
|
||||
labels = "--label #{DOCKER_IMAGE_NAME}"
|
||||
ports = PORTS.map { |p| "-p #{p}" }.join(" ")
|
||||
envs = ENVS.map { |k, v| "-e #{k}=#{v}" }.join(" ")
|
||||
volume = "--mount 'type=volume,source=fizzy,target=/rails/storage'"
|
||||
env_file = "--env-file #{ENV_FILE}"
|
||||
|
||||
on(HOSTS) do
|
||||
execute :docker, :ps, "-q", "-f", "\"label=#{DOCKER_IMAGE_NAME}\"", "|", "xargs", "-r", "docker", "stop"
|
||||
execute :docker, :run, "-d", labels, ports, envs, env_file, restart_policy, volume, DOCKER_TAGGED_IMAGE_NAME
|
||||
end
|
||||
end
|
||||
|
||||
announcing "Remove stopped containers from remote..." do
|
||||
on(HOSTS) do
|
||||
execute :docker, :container, :prune, "-f"
|
||||
execute :docker, :image, :prune, "-af"
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# If running the rails server then create or migrate existing database
|
||||
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
|
||||
if [ "${1}" == "./bin/thrust" ] && [ "${2}" == "./bin/rails" ] && [ "${3}" == "server" ]; then
|
||||
./bin/rails db:prepare
|
||||
fi
|
||||
|
||||
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# This file was generated by Bundler.
|
||||
#
|
||||
# The application 'thrust' is installed as part of a gem, and
|
||||
# this file is here to facilitate running it.
|
||||
#
|
||||
|
||||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
||||
|
||||
bundle_binstub = File.expand_path("bundle", __dir__)
|
||||
|
||||
if File.file?(bundle_binstub)
|
||||
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
||||
load(bundle_binstub)
|
||||
else
|
||||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
||||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
||||
end
|
||||
end
|
||||
|
||||
require "rubygems"
|
||||
require "bundler/setup"
|
||||
|
||||
load Gem.bin_path("thruster", "thrust")
|
||||
Reference in New Issue
Block a user