-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1e4926
commit e3e0463
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
set -x | ||
set -e | ||
set -o pipefail | ||
mkdir -p ~/.ssh | ||
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config | ||
chmod 600 ~/.ssh/config | ||
git clone "${head}" repo | ||
cd repo | ||
git config user.email "[email protected]" | ||
git config user.name "rultor" | ||
if [ "${as_root}" = "true" ]; then | ||
mkdir /home/r | ||
cp -R ./* /home/r | ||
rm -rf repo | ||
chmod a+x /home/r/script.sh | ||
/home/r/script.sh | ||
mv /home/r/repo . | ||
else | ||
shopt -s dotglob | ||
useradd -m -G sudo r | ||
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers | ||
cp -R /root/* /home/r | ||
cp -R ./* /home/r | ||
rm -rf repo | ||
chown -R r:r /home/r | ||
chmod a+x /home/r/script.sh | ||
su --login r --command /home/r/script.sh | ||
mv /home/r/repo . | ||
chown -R `whoami` repo | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'shellwords' | ||
require 'English' | ||
require 'yaml' | ||
|
||
module Rultor | ||
class Deploy | ||
def self.run | ||
create_script_sh | ||
rultor_yml = File.join(Dir.pwd, '.rultor.yml') | ||
@config = YAML.load_file(rultor_yml) | ||
execute( | ||
" | ||
docker run -it --rm -v `pwd`:/main -w='/main' #{self.env} --name=rultor-remote #{@config["docker"]["image"]} /main/entry.sh | ||
" | ||
) | ||
end | ||
|
||
private | ||
|
||
def self.execute(command) | ||
puts 'Executing command:' | ||
puts command | ||
system(command) | ||
end | ||
|
||
def self.create_script_sh | ||
system( | ||
" | ||
cat <<EOT > script.sh | ||
#!/bin/bash | ||
set -x | ||
set -e | ||
set -o pipefail | ||
shopt -s expand_aliases | ||
alias 'sudo=sudo -i' | ||
export HOME=/home/r | ||
cd \$HOME/repo | ||
EOT | ||
echo '${scripts[@]}' >> script.sh | ||
" | ||
) | ||
end | ||
|
||
def self.env | ||
str = "" | ||
variables = @config["env"] | ||
variables.merge!({ | ||
head: (%x[ git remote get-url origin ]).strip, | ||
head_branch: "master" | ||
}) | ||
variables.each do |key, value| | ||
str += "--env=#{key}=#{value} " | ||
end | ||
str | ||
end | ||
end | ||
end |