Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Katharina Fey
forge
Commits
699fbf4f
Commit
699fbf4f
authored
Apr 26, 2019
by
Katharina Fey
🏴
Browse files
adsasd
parent
310f4510
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/deploy.rs
View file @
699fbf4f
...
...
@@ -5,9 +5,9 @@ use crate::{config::Config, derive_key};
use
serde_json
::
Value
;
use
std
::{
collections
::
HashMap
,
fs
::{
remove_dir_all
,
remove_file
,
File
,
Permissions
},
fs
::{
remove_dir_all
,
remove_file
,
File
},
io
::
Write
,
process
::
Command
,
process
::
{
Command
,
Stdio
},
};
use
tempdir
::
TempDir
;
...
...
@@ -25,61 +25,37 @@ pub fn run(data: DeployData) {
let
repo
=
get_repo
(
&
data
.json
);
let
dir
=
TempDir
::
new
(
"forge"
)
.expect
(
"Failed to create temp working dir!"
);
let
dir_str
=
dir
.path
()
.as_os_str
()
.to_str
()
.expect
(
"Failed to format tmpdir path!"
);
let
dir_str
=
get_tmp_path
(
&
dir
);
println!
(
"Created temp dir {}"
,
dir_str
);
Command
::
new
(
"bash"
)
.current_dir
(
&
dir
)
.output
()
.unwrap
();
// Format paths required
let
git_dir
=
format!
(
"{}/configurations"
,
dir_str
);
let
deploy_key_path
=
format!
(
"{}/fucking_delete_me.priv"
,
dir_str
);
let
run_script
=
format!
(
"{}/forge_run.sh"
,
git_dir
);
let
deploy_key_path
=
format!
(
"{}/fucking_delete_me.priv"
,
dir
.path
()
.as_os_str
()
.to_str
()
.expect
(
"Failed to format deploy key path!"
)
);
let
run_script
=
format!
(
"{}/forge_run.sh"
,
dir
.path
()
.as_os_str
()
.to_str
()
.expect
(
"Failed to format deploy key path!"
)
);
println!
(
"Running `git clone`"
);
Command
::
new
(
"ssh-agent"
)
.args
(
&
[
run_command
(
&
dir_str
,
"ssh-agent"
,
&
[
"bash"
,
"-c"
,
&
format!
(
"'ssh-add {}; git clone --recursive {} configurations"
,
data
.repo_key
,
repo
),
])
.current_dir
(
&
dir
)
.output
()
.expect
(
"Failed to run git-clone command!"
);
println!
(
"Loading config from `{}`"
,
(
git_dir
.clone
()
+
"/.forge.yml"
)
],
);
let
mut
config
=
Config
::
load
((
git_dir
.clone
()
+
"/.forge.yml"
)
.as_str
())
.expect
(
"Invalid config!"
);
let
key
=
derive_key
(
data
.secret
,
data
.salt
);
// Run this to pre-cache a generation
C
ommand
::
new
(
"nixos-rebuild"
)
.args
(
&
[
"build"
,
"-I"
,
"nixos-config=configuration.nix"
])
.current_dir
(
&
git_dir
)
.output
()
.expect
(
"Failed to run git-clone command!"
);
run_c
ommand
(
&
git_dir
,
"nixos-rebuild"
,
&
[
"build"
,
"-I"
,
"nixos-config=configuration.nix"
],
);
let
cmd
=
&
config
.deploy.cmd
;
File
::
create
(
&
run_script
)
...
...
@@ -100,7 +76,7 @@ pub fn run(data: DeployData) {
eprintln!
(
"Key `auth.method` currently ignored!"
);
// Clear the mirror directory first
Command
::
new
(
"ssh"
)
let
mut
child
=
Command
::
new
(
"ssh"
)
.args
(
&
[
&
format!
(
"{}@localhost -i {}"
,
user
,
deploy_key_path
),
"bash"
,
...
...
@@ -109,13 +85,16 @@ pub fn run(data: DeployData) {
.env
(
"OUT_DIR"
,
&
git_dir
)
.env
(
"MIRROR"
,
mirror
)
.current_dir
(
&
git_dir
)
.output
()
.stdout
(
Stdio
::
inherit
())
.stderr
(
Stdio
::
inherit
())
.spawn
()
.map_err
(|
e
|
scrub
(
&
deploy_key_path
)
.map
(|
_
|
e
)
.unwrap
())
.expect
(
"Failed to run git-clone command!"
);
child
.wait
()
.unwrap
();
// Remove working state
scrub
(
&
deploy_key_path
);
remove_dir_all
(
&
dir
);
remove_dir_all
(
&
dir
)
.unwrap
()
;
}
/// Try to clear the private keyfile from disk
...
...
@@ -133,3 +112,26 @@ fn get_repo(json: &JsonMap) -> String {
_
=>
panic!
(
"Malformed json body!"
),
}
}
fn
get_tmp_path
(
dir
:
&
TempDir
)
->
String
{
dir
.path
()
.as_os_str
()
.to_str
()
.expect
(
"Failed to format deploy key path!"
)
.to_owned
()
}
/// Run a command while streaming it's stdout and stderr
fn
run_command
(
pwd
:
&
str
,
cmd
:
&
str
,
args
:
&
[
&
str
])
{
println!
(
"Running: `{} {} ...`"
,
cmd
,
args
[
0
]);
let
mut
child
=
Command
::
new
(
&
cmd
)
.args
(
args
)
.current_dir
(
pwd
)
.stdout
(
Stdio
::
inherit
())
.stderr
(
Stdio
::
inherit
())
.spawn
()
.unwrap
();
child
.wait
()
.expect
(
&
format!
(
"Failed to run {}"
,
cmd
));
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment