Browse Source

feat(user): Add the 'user' recipe

Signed-off-by: Jeremy MAURO <jeremy.mauro@gmail.com>
Jeremy MAURO 2 years ago
parent
commit
dea0089d16

+ 4 - 0
base.rb

@@ -33,6 +33,10 @@ named_run_list :apt, [
   'apt_repositories::_terraform',
 ]
 
+named_run_list :user, [
+  'workstation::_user',
+]
+
 named_run_list :genie, [
   'resolver_config::_dokken',
   'workstation::_genie',

+ 1 - 14
cookbooks/workstation/recipes/_git.rb

@@ -6,20 +6,7 @@
 
 include_recipe 'git'
 
-username, properties = node['my_workstation']['default_user'].first
-user username do
-  properties.each do |property, value|
-    send(property, value)
-  end
-end
-
-user_repo_directory = ::File.join(properties['home'], 'repo')
-
-directory user_repo_directory do
-  owner username
-  group username
-  recursive true
-end
+include_recipe 'workstation::_user'
 
 include_recipe 'workstation::_ssh-ident'
 

+ 23 - 0
cookbooks/workstation/recipes/_user.rb

@@ -0,0 +1,23 @@
+#
+# Cookbook:: workstation
+# Recipe:: _user
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+
+username, properties = node['my_workstation']['default_user'].first
+user username do
+  properties.each do |property, value|
+    send(property, value)
+  end
+end
+
+[
+  ::File.join(properties['home'], 'repo'),
+  ::File.join(properties['home'], '.aws'),
+].each do |dir|
+  directory dir do
+    owner username
+    group username
+    recursive true
+  end
+end

+ 3 - 0
cookbooks/workstation/recipes/default.rb

@@ -14,6 +14,9 @@ end
 # Configure repo
 include_recipe 'apt_repositories::_official'
 
+# User creation and directories
+include_recipe 'workstation::_user'
+
 # Setup podman
 include_recipe 'workstation::_podman'
 

+ 9 - 0
kitchen.yml

@@ -51,6 +51,15 @@ suites:
         - podman start chef-latest
       post_destroy:
         - podman volume prune -f
+  - name: workstation-user
+    provisioner:
+      named_run_list: 'user'
+    lifecycle:
+      pre_create:
+        - podman create --name chef-latest --replace docker.io/chef/chef:latest sh
+        - podman start chef-latest
+      post_destroy:
+        - podman volume prune -f
   - name: workstation-git
     provisioner:
       named_run_list: 'git'