From 6d614bb155190e950b792146f24591b2008420ca Mon Sep 17 00:00:00 2001 From: Chris Dostert Date: Sun, 11 Mar 2018 20:27:07 -0700 Subject: [PATCH] chore) initial commit --- .gitignore | 5 +++ .opspec/build/op.yml | 20 +++++++++++ .opspec/provision-image/Dockerfile | 3 ++ .opspec/provision-image/op.yml | 44 ++++++++++++++++++++++++ .opspec/release/op.yml | 51 ++++++++++++++++++++++++++++ .opspec/test/op.yml | 10 ++++++ .travis.yml | 8 +++++ CHANGELOG.md | 8 +++++ CODEOWNERS | 1 + README.md | 54 ++++++++++++++++++++++++++++++ cmd.js | 23 +++++++++++++ op.yml | 26 ++++++++++++++ 12 files changed, 253 insertions(+) create mode 100644 .gitignore create mode 100644 .opspec/build/op.yml create mode 100644 .opspec/provision-image/Dockerfile create mode 100644 .opspec/provision-image/op.yml create mode 100644 .opspec/release/op.yml create mode 100644 .opspec/test/op.yml create mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 CODEOWNERS create mode 100644 README.md create mode 100644 cmd.js create mode 100644 op.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ad0969 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Jetbrains +.idea/ + +# opctl +*args*.yml \ No newline at end of file diff --git a/.opspec/build/op.yml b/.opspec/build/op.yml new file mode 100644 index 0000000..c57223e --- /dev/null +++ b/.opspec/build/op.yml @@ -0,0 +1,20 @@ +name: build +description: builds the package +inputs: + srcDir: + dir: + default: . +outputs: + srcDir: + dir: {} +run: + serial: + - op: + pkg: { ref: test } + inputs: { srcDir } + - op: + pkg: { ref: github.com/opspec-pkgs/_.pkg.bootstrap#1.0.0 } + inputs: + srcDir: + outputs: + srcDir: \ No newline at end of file diff --git a/.opspec/provision-image/Dockerfile b/.opspec/provision-image/Dockerfile new file mode 100644 index 0000000..a7fcff6 --- /dev/null +++ b/.opspec/provision-image/Dockerfile @@ -0,0 +1,3 @@ +FROM node:9.5.0-alpine + +RUN yarn add js-yaml \ No newline at end of file diff --git a/.opspec/provision-image/op.yml b/.opspec/provision-image/op.yml new file mode 100644 index 0000000..494bb30 --- /dev/null +++ b/.opspec/provision-image/op.yml @@ -0,0 +1,44 @@ +name: provision-image +description: | + Provisions image for the pkg w/ name `opspecpkgs/$(opDotYml.name):${opDotYml.version}`. + + > Before first use, a Dockerfile MUST be added to `.opspec/provision-image` +inputs: + dockerUsername: + string: + constraints: { minLength: 1 } + description: user for logging in to docker hub + dockerPassword: + string: + constraints: { minLength: 1 } + description: password for logging in to docker hub + isSecret: true + srcDir: + dir: + default: . +run: + serial: + - op: + pkg: { ref: github.com/opspec-pkgs/yaml.parse#1.0.0 } + inputs: { yaml: $(srcDir/op.yml) } + outputs: { opDotYml: result } + - container: + image: { ref: 'alpine:3.6' } + cmd: [sh, -ce, 'echo -n opspecpkgs/${opName#*/*/}:$(opDotYml.version) > /imageName'] + envVars: + opName: $(opDotYml.name) + files: + /imageName: $(imageName) + - op: + pkg: { ref: github.com/opspec-pkgs/docker.image.build#2.0.1 } + inputs: + dockerfile: $(/Dockerfile) + imageName: + outputs: { imageTar } + - op: + pkg: { ref: github.com/opspec-pkgs/docker.image.push#2.0.1 } + inputs: + imageTar: + imageName: + username: $(dockerUsername) + password: $(dockerPassword) \ No newline at end of file diff --git a/.opspec/release/op.yml b/.opspec/release/op.yml new file mode 100644 index 0000000..53d04a1 --- /dev/null +++ b/.opspec/release/op.yml @@ -0,0 +1,51 @@ +name: release +description: releases the package +inputs: + githubUsername: + string: + constraints: { minLength: 1 } + description: user for logging in to github + githubPassword: + string: + constraints: { minLength: 1 } + description: password for logging in to github + isSecret: true + srcDir: + dir: + default: . +outputs: + srcDir: + dir: {} +run: + serial: + - op: + pkg: { ref: build } + inputs: + srcDir: + outputs: + srcDir: + - op: + pkg: { ref: github.com/opspec-pkgs/yaml.parse#1.0.0 } + inputs: { yaml: $(srcDir/op.yml) } + outputs: { opDotYml: result } + - op: + pkg: { ref: github.com/opspec-pkgs/git.resolve-commit#1.0.2 } + inputs: { dotGitDir: $(srcDir/.git) } + outputs: { commit: } + - container: + image: { ref: 'alpine:3.6' } + cmd: [sh, -ce, 'echo -n ${opName#*/*/} > /opRepo'] + envVars: + opName: $(opDotYml.name) + files: + /opRepo: $(opRepo) + - op: + pkg: { ref: github.com/opspec-pkgs/github.release.create#1.0.0 } + inputs: + owner: opspec-pkgs + repo: $(opRepo) + loginUsername: $(githubUsername) + loginPassword: $(githubPassword) + tag: $(opDotYml.version) + commitish: $(commit) + name: $(opDotYml.version) \ No newline at end of file diff --git a/.opspec/test/op.yml b/.opspec/test/op.yml new file mode 100644 index 0000000..d858d06 --- /dev/null +++ b/.opspec/test/op.yml @@ -0,0 +1,10 @@ +name: test +description: tests the package +inputs: + srcDir: + dir: + default: . +run: + op: + pkg: { ref: github.com/opspec-pkgs/opspec.pkg.validate#1.0.0 } + inputs: { pkg: $(srcDir) } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fec2005 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: generic +sudo: required +before_script: +- curl -L https://bin.equinox.io/c/4fmGop7rntx/opctl-beta-linux-amd64.tgz | sudo tar -xzv -C /usr/local/bin +services: +- docker +script: +- opctl run build \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cbd4602 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Change Log + +All notable changes will be documented in this file in accordance with +[![keepachangelog 1.0.0](https://img.shields.io/badge/keepachangelog-1.0.0-brightgreen.svg)](http://keepachangelog.com/en/1.0.0/) + +## \[Unreleased] + +## \[1.0.0] 2018-03-11 \ No newline at end of file diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..60761a7 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @opspec-pkgs/maintainers diff --git a/README.md b/README.md new file mode 100644 index 0000000..288a56c --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +[![Build Status](https://travis-ci.org/opspec-pkgs/opspec.dir.list-ops.svg?branch=master)](https://travis-ci.org/opspec-pkgs/opspec.dir.list-ops) + +# Problem statement + +lists ops in a directory + +# Format + +this version of the pkg is in [![opspec 0.1.5](https://img.shields.io/badge/opspec-0.1.5-brightgreen.svg?colorA=6b6b6b&colorB=fc16be)](https://opspec.io/0.1.5/packages.html) format + +# Example usage + +## Install + +```shell +opctl pkg install github.com/opspec-pkgs/opspec.dir.list-ops#1.0.0 +``` + +## Run + +``` +opctl run github.com/opspec-pkgs/opspec.dir.list-ops#1.0.0 +``` + +## Compose + +```yaml +op: + pkg: { ref: github.com/opspec-pkgs/opspec.dir.list-ops#1.0.0 } + inputs: + # params w/ default + dir: + outputs: + ops: +``` + +# Support + +join us on +[![Slack](https://opspec-slackin.herokuapp.com/badge.svg)](https://opspec-slackin.herokuapp.com/) +or +[open an issue](https://github.com/opspec-pkgs/opspec.dir.list-ops/issues) + +# Releases + +releases are versioned according to +[![semver 2.0.0](https://img.shields.io/badge/semver-2.0.0-brightgreen.svg)](http://semver.org/spec/v2.0.0.html) +and [tagged](https://git-scm.com/book/en/v2/Git-Basics-Tagging); see +[CHANGELOG.md](CHANGELOG.md) for release notes + +# Contributing + +see +[project/CONTRIBUTING.md](https://github.com/opspec-pkgs/project/blob/master/CONTRIBUTING.md) diff --git a/cmd.js b/cmd.js new file mode 100644 index 0000000..e634257 --- /dev/null +++ b/cmd.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const path = require('path'); +const jsYaml = require('js-yaml'); +const PATH_PREFIX = '/dir/'; + +const listOps = dir => + fs.readdirSync(dir) + .reduce((files, file) => { + if (fs.statSync(path.join(dir, file)).isDirectory()) { + files.push(...listOps(path.join(dir, file))) + } else if(file === 'op.yml') { + const opYmlPath = path.join(dir, file); + const op = jsYaml.safeLoad(fs.readFileSync(opYmlPath)) + files.push({ + path: opYmlPath.slice(PATH_PREFIX.length), + name: op.name, + }); + } + return files; + }, + []); + +fs.writeFileSync('/ops', JSON.stringify(listOps(PATH_PREFIX))); \ No newline at end of file diff --git a/op.yml b/op.yml new file mode 100644 index 0000000..7cf6cfd --- /dev/null +++ b/op.yml @@ -0,0 +1,26 @@ +name: github.com/opspec-pkgs/opspec.dir.list-ops +description: lists ops in a directory +inputs: + dir: + dir: + description: directory to (recursively) list ops from + default: . +outputs: + ops: + array: + description: lists name & path of ops in the directory + constraints: + items: + properties: + name: {} + path: {} +version: 1.0.0 +run: + container: + image: { ref: 'opspecpkgs/opspec.dir.list-ops:1.0.0' } + cmd: [node, /cmd.js] + dirs: + /dir: $(dir) + files: + /cmd.js: + /ops: $(ops) \ No newline at end of file