Onboarding für neue Entwickler mit Ansible

Ihr neuer Entwickler hat gerade einen Arbeitsvertrag unterschrieben und ist bereit, 15 Aufgaben pro Tag mit brennenden Augen zu erledigen. Es gibt nur ein Hindernis auf seinem Weg - einen neuen Laptop, der noch nicht richtig konfiguriert wurde. In den meisten Fällen wird der Prozess zum Einrichten der Umgebung in einem Dokument beschrieben, das an einen neuen Entwickler ausgegeben wird. Wir sind nicht sehr weit gegangen und haben auch eine solche Liste gemacht.





  1. Xcode installieren





  2. Einrichten eines lokalen Git-Repositorys





  3. Umgebung einrichten





  4. Projektaufbau





  5. Lesen Sie die Dokumentation





  6. Einrichten eines Task-Trackers (Jira / Youtrack)





Um keine wertvolle Entwicklerzeit mit dem manuellen Einrichten eines neuen Laptops zu verschwenden, haben wir die Schritte 3 und 4 automatisiert, weil Sie sind am arbeitsintensivsten.





Schauen wir uns also zuerst die Einrichtung der Umgebung an.





Umgebung einrichten

In unserem Fall besteht die Einrichtung der Umgebung aus mehreren Punkten:





1. Installieren von Brühabhängigkeiten





2.    mint





3.    ruby





4.    python





, Ansible. , , , , – playbooks.





, ansible .





:





#!/usr/bin/env bash

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python get-pip.py

sudo pip install ansible

cd $(dirname $0) && ansible-playbook main.yml
      
      



:





  1. pip





  2. Ansible





  3. main.yml







, main.yml



.





- hosts: localhost
  roles:
	- common_setup
      
      



hosts , , , roles , , .





roles , ,





(meta, tasks vars) main.yml



.





main.yml, roles .





tasks, , . , Ruby rvm.





---

- name: Check if RVM already installed

  stat: path=~/.rvm

  register: rvmdir

  changedwhen: false

- name: Install RVM for a user

  command: bash -c "\curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles"

  when: rvmdir.stat.exists == False

- name: Add RVM to profile

  command: bash -c "~/.rvm/bin/rvm get stable --auto-dotfiles"

  when: rvmdir.stat.exists == False

- name: Add RVM to zshrc

  command: bash -c "echo '\n[ -s ${HOME}/.rvm/scripts/rvm ] && source ${HOME}/.rvm/scripts/rvm' >> ~/.zshrc"

  when: rvmdir.stat.exists == False

- name: Install {{ rubyversion }}

  command: bash -c "~/.rvm/bin/rvm install {{ rubyversion }}"

  when: rvmdir.stat.exists == False

- name: Set Ruby Default

  command: bash -c "~/.rvm/bin/rvm --default use {{ rubyversion }}"

  when: rvmdir.stat.exists == False

- name: Install Ruby Gems required for iOS app developement

  gem: name={{ item.name }} version={{ item.version }} state={{ if item.version is defined nil else latest }}

  withitems: "{{ rubygems_packages_to_install }}"

  when: rvmdir.stat.exists == False
      
      



  1. , rvm.





    name



    -





    stat



    - rvm





    register







    changed_when







    , , false. .





  2. rvm.





    name



    -





    command



    -





    when



    -





    rvm, rvmdir



    .





  3. rvm. .





  4. .zshrc . MacOS Catalina , zsh .





  5. Ruby. , vars. main.yml



    :





    rubyversion: ruby-2.6.5







  6. Ruby





  7. , bundler. vars, :





    rubygems_packages_to_install:







      - name: bundler







    version:2.1.4







, .





.





:





#!/usr/bin/ruby

require 'FileUtils'
require 'colorize'

RESOURCES_DIRECTORY = './Scripts/Resources'.freeze
XCODE_DIRECTORY = '~/Library/Developer/Xcode'.freeze

def setup_git_hooks
  puts "Setting up git hooks".blue.bold

  git_hooks_path = '.git/hooks'
  FileUtils.mkdir_p(git_hooks_path)

  Dir["#{RESOURCES_DIRECTORY}/Git hooks/*"].each do |file|
	FileUtils.cp_r(file, "#{git_hooks_path}/#{File.basename(file)}")
  end
end

def setup_file_templates
  puts "\nSetting up file templates".blue.bold

  file_templates_path = File.expand_path("#{XCODE_DIRECTORY}/Templates/File Templates/Tests")
  FileUtils.mkdir_p(file_templates_path)

  Dir["#{RESOURCES_DIRECTORY}/Templates/*.xctemplate"].each do |file|
	FileUtils.cp_r(file, "#{file_templates_path}/#{File.basename(file)}")
  end
end

def setup_xcode_snippets
  puts "\nSetting up xcode snippets".blue.bold

  need_to_reboot_xcode = false

  code_snippets_path = File.expand_path("#{XCODE_DIRECTORY}/UserData/CodeSnippets")
  FileUtils.mkdir_p(code_snippets_path)

  Dir["#{RESOURCES_DIRECTORY}/Snippets/*.codesnippet"].each { |file|
	path = "#{code_snippets_path}/#{File.basename(file)}"
	next if File.file?(path)
	need_to_reboot_xcode = true
	FileUtils.cp_r(file, path)
  }

  return unless need_to_reboot_xcode

  puts 'Quiting Xcode'.blue
  system('killall Xcode')
end

def setup_gems
  puts "\nSetting up gems".blue.bold
  system('bundle install')
end

def setup_mocks
  puts "\nSetting up mocks".blue.bold
  system('cd $(pwd) && swiftymocky generate')
end

def setup_projects
  puts "\nSetting up projects".blue.bold
  system('bundle exec rake update_projects')
end

# Steps

Dir.chdir("#{File.expand_path(File.dirname(__FILE__))}/..")

setup_git_hooks
setup_file_templates
setup_xcode_snippets
setup_gems
setup_mocks
setup_projects
      
      



:





  1. -. , .





  2. .





  3. .





  4. .





  5. .





  6. .





, , . Carthage XcodeGen.





1 , . , , . 





. , -, .








All Articles