mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-08-21 22:43:47 +09:00
Port over release script
Co-Authored-By: Kevin McConnell <kevin@37signals.com>
This commit is contained in:
@@ -45,5 +45,8 @@
|
||||
# Ignore ignore
|
||||
.dockerignore
|
||||
|
||||
# Don't include our README
|
||||
/README.md
|
||||
|
||||
# Ignore test files
|
||||
/test/
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# syntax = docker/dockerfile:1
|
||||
|
||||
# Make sure it matches the Ruby version in .ruby-version and Gemfile
|
||||
ARG RUBY_VERSION=3.4.7
|
||||
FROM ruby:$RUBY_VERSION-slim as base
|
||||
|
||||
# Install the tools we need
|
||||
RUN apt update && apt install -y zip
|
||||
|
||||
# Export from this folder
|
||||
WORKDIR /campfire
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Create the archive
|
||||
CMD ["zip", "-r", "/campfire.zip", "."]
|
||||
Executable
+95
@@ -0,0 +1,95 @@
|
||||
#!/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
|
||||
|
||||
ARCH = "linux/amd64,linux/arm64"
|
||||
BUILDER_NAME = "campfire-builder"
|
||||
GIT_SHA = `git rev-parse HEAD`.strip
|
||||
VERSION = ARGV[0]
|
||||
|
||||
DOCKER_IMAGE_NAME = "registry.once.com/campfire"
|
||||
DOCKER_LATEST_IMAGE_NAME = [ DOCKER_IMAGE_NAME, :latest ].join(":")
|
||||
DOCKER_TAGGED_IMAGE_NAME = [ DOCKER_IMAGE_NAME, GIT_SHA ].join(":")
|
||||
|
||||
EXPORT_IMAGE_NAME = "campfire-export"
|
||||
EXPORT_DOCKERFILE = "Dockerfile-export"
|
||||
EXPORT_TARGET_NAME = "campfire.zip"
|
||||
EXPORT_REMOTE_USER = "app"
|
||||
EXPORT_DEPLOY_HOSTS = %w[ once-store-app-101 once-store-app-102 ]
|
||||
EXPORT_DEPLOY_LOCATION = "/local/app/product_releases/"
|
||||
|
||||
abort "You must specify a version, e.g. `bin/release 1.0.0`" unless VERSION
|
||||
|
||||
def announcing(message)
|
||||
puts "\n\e[1;36m#{message}\e[0m"
|
||||
yield
|
||||
end
|
||||
|
||||
on(:local) do
|
||||
builder_found = test :docker, :buildx, :inspect, BUILDER_NAME
|
||||
|
||||
unless builder_found
|
||||
announcing "Setting up builder..." do
|
||||
execute :docker, :buildx, :create, "--name", BUILDER_NAME
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
announcing "Tagging as #{VERSION}" do
|
||||
on(:local) do
|
||||
execute :git, :fetch, :origin, "--tags"
|
||||
|
||||
unless system "git tag -a v#{VERSION} -m 'Version #{VERSION}\n\n- list important changes here' -e"
|
||||
abort "Failed to create tag; check that the version doesn't already exist"
|
||||
end
|
||||
|
||||
unless test :git, :push, "--tags"
|
||||
abort "Failed to push tag; check that the version doesn't already exist"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
announcing "Building and pushing image..." do
|
||||
versioning = "--build-arg APP_VERSION=#{VERSION} --build-arg GIT_REVISION=#{GIT_SHA}"
|
||||
|
||||
on(:local) do
|
||||
execute :docker, :buildx, :build, "--builder", BUILDER_NAME, "--push", versioning, "-t", DOCKER_LATEST_IMAGE_NAME, "-t", DOCKER_TAGGED_IMAGE_NAME, "--platform", ARCH, "."
|
||||
end
|
||||
end
|
||||
|
||||
SSHKit::Backend::Netssh.configure do |ssh|
|
||||
ssh.connection_timeout = 30
|
||||
ssh.ssh_options = { user: EXPORT_REMOTE_USER }
|
||||
end
|
||||
|
||||
announcing "Building source code ZIP image..." do
|
||||
on(:local) do
|
||||
execute :docker, :build, "-t", EXPORT_IMAGE_NAME, "-f", EXPORT_DOCKERFILE, "."
|
||||
end
|
||||
end
|
||||
|
||||
announcing "Exporting source code to ZIP..." do
|
||||
on(:local) do
|
||||
execute :docker, :run, "--name", EXPORT_IMAGE_NAME, EXPORT_IMAGE_NAME
|
||||
execute :docker, :cp, "#{EXPORT_IMAGE_NAME}:/#{EXPORT_TARGET_NAME}", "tmp/#{EXPORT_TARGET_NAME}"
|
||||
execute :docker, :rm, EXPORT_IMAGE_NAME
|
||||
end
|
||||
end
|
||||
|
||||
announcing "Uploading source code ZIP..." do
|
||||
on(EXPORT_DEPLOY_HOSTS) do
|
||||
within EXPORT_DEPLOY_LOCATION do
|
||||
upload! "tmp/#{EXPORT_TARGET_NAME}", EXPORT_TARGET_NAME
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user