Coder Social home page Coder Social logo

provisioning-bash's Introduction

provisioning-bash

Build Status MIT License

provisioning-bash is collection of scripts for OS provisioning.

All scripts are written by bash so they are easy and useful for your server provisioning.

Structure

  • ./entry.sh is entry point script for provisioning
  • ./PLATFORM is directory of each PLATFORM (ubuntu18, centos7, etc...)
  • ./PLATFORM/SCRIPT is script for provisioning (ex. docker.sh, apache.sh, etc...)
  • ./PLATFORM/files/SCRIPT is directory of configuration files
    • ex. ./PLATFORM/files/SCRIPT/etc/apache2/conf/httpd.conf is original file of /etc/apache2/conf/httpd.conf.
      • ./PLATFORM/files/SCRIPT is path prefix. This file supposes that will be copied to same path of target server or container.

Usage

Manualy

# <PLATFORM> is platform environment (ex. "amazon2", "ubuntu18" and more)
# <SCRIPT> is provisioning script file name

curl -fLsS https://git.io/prv-bash | bash -s <PLATFORM> <SCRIPT> [SOME ARGS...]

Docker

FROM ubuntu:18.04

MAINTAINER goldeneggg

RUN mkdir /tmp/prv-bash
WORKDIR /tmp/prv-bash

# entry.sh on remote github.com is copied to local container path
ADD https://git.io/prv-bash /tmp/prv-bash/entry.sh

# kick entry.sh
#   1st arg: platform
#   2nd arg: script name
RUN bash entry.sh ubuntu18 init.sh

Vagrant

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/bionic64"
  config.disksize.size = '30GB'
  machines = [
    {
      hostname:  "vmubuntu14",
      ip:  "192.168.56.180",
      memory:  4096,
      cpus:  2,
      forwarded_ports:  {
      }
    }
  ]

  # Set your platform
  platform = 'ubuntu14'

  # Set your provisoners
  # - 'name' is script file name
  # - 'root' is privilege setting. if you'd like to run script as root user, set true
  # - 'args' is ARGV setting for assigned script
  provisioning_scripts = [
    { name: mysql.sh, root: true, args: [] }
  ]

  machines.each do |m|
    config.vm.define m[:hostname] do |d|
      d.vm.hostname = m[:hostname]
      d.vm.network :private_network, ip: m[:ip]

      d.vm.provider :virtualbox do |vb|
        vb.memory = m[:memory]
        vb.cpus = m[:cpus]
      end

      m[:forwarded_ports].each do |guest_port, host_port|
        d.vm.network :forwarded_port, host: host_port, guest: guest_port
      end

      # provisioning scripts
      provisioning_scripts.each do |prv|
        d.vm.provision :shell do |s|
          s.path = "https://git.io/prv-bash"
          s.args = [platform, prv["name"]] + prv["args"]
          s.privileged = prv["root"]
        end
      end
    end
  end
end

EC2 user-data

EC2 user-data for Amazon Linux 2 as follows:

(original file is here)

#!/bin/bash

WORKDIR=/tmp/work
ROOT_WORKDIR=/tmp/root_work
ENTRY=entry.sh

# "amazon1" or "amazon2"
PLATFORM=amazon2

# assign your provisioning scripts for root user into ROOT_TARGETS variable
ROOT_TARGETS=("init.sh")

if [ ${#ROOT_TARGETS[@]} -ne 0 ]
then
  echo "ROOT_TARGETS=${ROOT_TARGETS}"
  sudo mkdir -p ${ROOT_WORKDIR}
  sudo curl -fLsS https://git.io/prv-bash -o ${ROOT_WORKDIR}/${ENTRY}
  sudo chmod +x ${ROOT_WORKDIR}/${ENTRY}

  for t in ${ROOT_TARGETS[@]}
  do
    echo "Run ${t} by root"
    sudo bash ${ROOT_WORKDIR}/${ENTRY} ${PLATFORM} ${t}
  done
fi

# assign your provisioning scripts for general user into TARGETS variable
TARGETS=()

if [ ${#TARGETS[@]} -ne 0 ]
then
  echo "TARGETS=${TARGETS}"
  mkdir -p ${WORKDIR}
  curl -fLsS https://git.io/prv-bash -o ${WORKDIR}/${ENTRY}
  chmod +x ${WORKDIR}/${ENTRY}

  for t in ${TARGETS[@]}
  do
    echo "Run {t} by user"
    bash ${WORKDIR}/${ENTRY} ${PLATFORM} ${t}
  done
fi

License

LICENSE file for details.

provisioning-bash's People

Contributors

goldeneggg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.