浏览代码

Add extra tasks in builtins (thanks to Aurélien Vermylen):

- wget, unzip, patch and carriage return conversions in os
- createdb-with-owner in pg
Bertrand Chenal 7 年之前
父节点
当前提交
cada5e093c
共有 4 个文件被更改,包括 59 次插入16 次删除
  1. 7 7
      pkg/az.yaml
  2. 0 2
      pkg/git.yaml
  3. 41 1
      pkg/os.yaml
  4. 11 6
      pkg/pg.yaml

+ 7 - 7
pkg/az.yaml

@@ -3,19 +3,19 @@ tasks:
   create-vm:
   create-vm:
      desc: Create a new azure VM
      desc: Create a new azure VM
      local: >
      local: >
-       az vm create -n "bio-pm-prove-{vm_name}" -g "{ressource_group}"
-       --image UbuntuLTS  --admin-username deploy --ssh-key-value deploy_rsa.pub
-       --data-disk-sizes-gb 100 --public-ip-address "" --subnet "{subnet}"
+       az vm create -n "{vm_name}" -g "{ressource_group}"
+       --image UbuntuLTS  --admin-username {vm_admin} --ssh-key-value {ssh_pubkey}
+       --data-disk-sizes-gb {vm_disk_size} --public-ip-address "" --subnet "{subnet}"
      once: true
      once: true
   delete-vm-only:
   delete-vm-only:
      desc: Delete azure VM
      desc: Delete azure VM
-     local: az vm delete -n "bio-pm-prove-{vm_name}"  -g "RG-DC-BUS-QUANTS" -y
+     local: az vm delete -n "{vm_name}"  -g "RG-DC-BUS-QUANTS" -y
      once: true
      once: true
   show-disk:
   show-disk:
      desc: Read disk id
      desc: Read disk id
      local: >-
      local: >-
        az vm show -g "RG-DC-BUS-QUANTS" --query "{query}"
        az vm show -g "RG-DC-BUS-QUANTS" --query "{query}"
-       -n "bio-pm-prove-{vm_name}"
+       -n "{vm_name}"
      once: true
      once: true
   delete-disk:
   delete-disk:
      desc: Delete azure disk
      desc: Delete azure disk
@@ -43,12 +43,12 @@ tasks:
      desc: Query azure vm by name for ip
      desc: Query azure vm by name for ip
      local: >
      local: >
        az vm list-ip-addresses
        az vm list-ip-addresses
-       --query "[?virtualMachine.name=='bio-pm-prove-{vm_name}']
+       --query "[?virtualMachine.name=='{vm_name}']
        .virtualMachine.network.privateIpAddresses[0]"
        .virtualMachine.network.privateIpAddresses[0]"
      once: true
      once: true
   vm-info:
   vm-info:
      desc: Query azure vm by name for info
      desc: Query azure vm by name for info
-     local: az vm list --query "[?name=='bio-pm-prove-{vm_name}']"
+     local: az vm list --query "[?name=='{vm_name}']"
      once: true
      once: true
   fix-hosts:
   fix-hosts:
     desc: "See: https://github.com/Microsoft/WSL/issues/491"
     desc: "See: https://github.com/Microsoft/WSL/issues/491"

+ 0 - 2
pkg/git.yaml

@@ -8,5 +8,3 @@ tasks:
   pull:
   pull:
     desc: Update codebase
     desc: Update codebase
     run: cd src/prove && git pull
     run: cd src/prove && git pull
-    env:
-      ssh_user: prove

+ 41 - 1
pkg/os.yaml

@@ -71,7 +71,6 @@ tasks:
       sleep 1
       sleep 1
       mkfs -t ext4 {device}1
       mkfs -t ext4 {device}1
       fi
       fi
-
   append-line:
   append-line:
     desc: Append line to file
     desc: Append line to file
     run: >-
     run: >-
@@ -80,3 +79,44 @@ tasks:
   add-user:
   add-user:
     desc: Add a new user
     desc: Add a new user
     run: id {user} || sudo adduser {user} --disabled-login --gecos ""
     run: id {user} || sudo adduser {user} --disabled-login --gecos ""
+  wget:
+    desc: Download a file
+    run: test -f {file} || wget -O {file} {url}
+  unzip:
+    desc: Unzip a zip file
+    run: test -d {dir} || unzip {file} -d {dir}
+  patch:
+    # Do not leave .rej file if patch was already applied.
+    # Thus the "rm" on last line.
+    desc: Patch a file with a specific local diff file
+    run: |
+      patch --ignore-whitespace --reject-file=/dev/null -uN {file} << EOF
+      {diff_string}
+      EOF
+  send-rmcr:
+    desc: Send a file but remove its carriage returns before.
+    multi:
+      - task: send
+      - run: "tr -d '\r' < {to} > {to}-tmp"
+      - task: move
+        env:
+          from: "{to}-tmp"
+  sudo-send-rmcr:
+    desc: Combine send & sudo-move, and remove carriage returns
+    multi:
+      - task: send
+        env:
+          to: "/tmp/{tmppath}"
+      - task: rmcr
+        env:
+          from: "/tmp/{tmppath}"
+        sudo: true
+      - task: remove
+        env:
+          path: "/tmp/{tmppath}"
+  rmcr:
+    desc: remove carriage returns and move file
+    run: "tr -d '\r' < {from} | tee {to} > /dev/null"
+  unlink:
+    desc: remove a symlink
+    run: "test -L {path} && unlink {path}"

+ 11 - 6
pkg/pg.yaml

@@ -7,13 +7,18 @@ tasks:
       then createuser {pg_user} -d
       then createuser {pg_user} -d
       fi
       fi
   createdb:
   createdb:
-    desc: Create a new db
-    run: |
-      if ! psql -l | grep {db_name} &> /dev/null
-      then createdb {db_name}
-      fi
-
+    desc: Create a new db for default user
+    multi:
+      - task: createdb-with-owner
+    env:
+      db_owner: "{ssh_user}"
   alter-passwd:
   alter-passwd:
     desc: Alter user password
     desc: Alter user password
     sudo: postgres
     sudo: postgres
     run: psql -c "ALTER USER {pg_user} WITH PASSWORD '{pg_password}'"
     run: psql -c "ALTER USER {pg_user} WITH PASSWORD '{pg_password}'"
+  createdb-with-owner:
+    desc: Create a new db with a specific owner
+    run: |
+      if ! psql -l | grep {db_name} &> /dev/null
+      then createdb -O {db_owner} {db_name}
+      fi