Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

references from SAPI project, setup docker compose for cap deployment #257

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
references from SAPI project, setup docker compose for cap deployment
leonardow-unep-wcmc committed Dec 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit c0a1cca211f8e957e36779e3fc38344d60471fb6
57 changes: 57 additions & 0 deletions Dockerfile.cap-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM --platform=linux/amd64 ruby:2.5.0-slim-stretch

ENV BUNDLE_PATH="/usr/local/bundle"

# Install dependencies
RUN echo "deb http://archive.debian.org/debian stretch main contrib non-free" > /etc/apt/sources.list && \
echo "deb http://archive.debian.org/debian-security stretch/updates main contrib non-free" >> /etc/apt/sources.list && \
echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until && \
apt-get update -qq && \
apt-get install --no-install-recommends -y \
curl build-essential zlib1g-dev git libpq-dev \
# Editor
vim nano \
# For RVM
gnupg procps curl libssl-dev dirmngr \
# ssh/capistrano
openssh-client \
# # For webpack-dev-server
# libsodium-dev \
# # For mimemagic gem
# shared-mime-info \
# Clean up
&& rm -rf /var/lib/apt/lists/*

WORKDIR /ocean-plus-habitats

# https://stackoverflow.com/questions/43612927/how-to-correctly-install-rvm-in-docker
RUN gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
RUN curl -sSL https://get.rvm.io | bash -s
RUN /bin/bash -l -c ". /etc/profile.d/rvm.sh && rvm install 2.5.0"
# RVM installed in multi-user mode. However cap assume rvm is installed in single user mode.
# Create a soft link to fake it.
RUN mkdir -p ~/.rvm/bin && ln -s /usr/local/rvm/bin/rvm ~/.rvm/bin/rvm

COPY Gemfile /ocean-plus-habitats/Gemfile
COPY Gemfile.lock /ocean-plus-habitats/Gemfile.lock

ENV BUNDLE_SILENCE_ROOT_WARNING=1
RUN /bin/bash -c "source /etc/profile.d/rvm.sh \
&& gem install bundler:1.17.3 \
&& bundle"

ENTRYPOINT ["/bin/bash", "-l"]

##########################################
## Run the following in container
##########################################
# /bin/bash --rcfile cap-deploy-shell.sh
# [Enter your passphrase]
# root@commit:/ocean-plus-habitats$ CAP_BRANCH=<branch> cap staging deploy
#
##########################################
# Alternatively, from outside docker
##########################################
# docker exec -it sapi-cap-deploy /bin/bash --rcfile cap-deploy-shell.sh
# [Enter your passphrase]
# root@commit:/ocean-plus-habitats# CAP_BRANCH=<branch> cap staging deploy
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end

# The most popular solution to the EU cookie law for Rails applications.
# The most popular solution to the EU cookie law for Rails applications.
gem 'cookieconsent'
# prefix rails c commands with ap for pretty results
gem 'awesome_print'
@@ -76,6 +76,13 @@ group :development do
gem 'capistrano-bundler', '~> 1.1', require: false
gem 'capistrano-passenger', '~> 0.1.1', require: false
gem 'bullet'

##
# For capistrano ssh in docker
gem 'rbnacl', '4.0.2'
gem 'rbnacl-libsodium', '1.0.16'
gem 'bcrypt_pbkdf', '1.1.0'
gem 'ed25519', '1.2.4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ GEM
sshkit (>= 1.6.1, != 1.7.0)
arel (8.0.0)
awesome_print (1.8.0)
bcrypt_pbkdf (1.1.0)
bindex (0.8.1)
builder (3.2.3)
bullet (6.1.4)
@@ -100,6 +101,7 @@ GEM
dotenv-rails (2.7.5)
dotenv (= 2.7.5)
railties (>= 3.2, < 6.1)
ed25519 (1.2.4)
erubi (1.9.0)
execjs (2.7.0)
factory_bot (6.2.0)
@@ -180,6 +182,10 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
rbnacl (4.0.2)
ffi
rbnacl-libsodium (1.0.16)
rbnacl (>= 3.0.1)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
@@ -267,6 +273,7 @@ PLATFORMS

DEPENDENCIES
awesome_print
bcrypt_pbkdf (= 1.1.0)
bullet
byebug
capistrano (~> 3.11.0)
@@ -281,6 +288,7 @@ DEPENDENCIES
cookieconsent
database_cleaner
dotenv-rails (~> 2.2, >= 2.2.1)
ed25519 (= 1.2.4)
factory_bot_rails
faker
httparty (~> 0.16.2)
@@ -289,6 +297,8 @@ DEPENDENCIES
pg (>= 0.18, < 2.0)
puma (~> 4.3)
rails (~> 5.1.5)
rbnacl (= 4.0.2)
rbnacl-libsodium (= 1.0.16)
rspec-rails (~> 4.0.2)
rubyzip (>= 1.0.0)
sassc-rails (~> 2.1.0)
12 changes: 12 additions & 0 deletions cap-deploy-shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#/bin/bash
mkdir -p ~/.ssh;

cp /run/secrets/host_ssh_key ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519

cp /run/secrets/host_ssh_config ~/.ssh/config
chmod 600 ~/.ssh/config

source /etc/profile.d/rvm.sh
eval "$(ssh-agent -s)"
ssh-add
27 changes: 27 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

networks:
ocean-plus-habitats:
driver: bridge

services:
deploy:
container_name: ocean-plus-habitats-cap-deploy
build:
context: ./
dockerfile: Dockerfile.cap-deploy
volumes:
- '.:/ocean-plus-habitats'
networks:
- ocean-plus-habitats
stdin_open: true
tty: true
secrets:
- host_ssh_key
- host_ssh_config

secrets:
host_ssh_key:
file: ~/.ssh/id_ed25519
host_ssh_config:
file: ~/.ssh/config