Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const fetch = require('node-fetch').default;
const expect = require('chai').expect;
const execa = require('execa');

Expand Down
5 changes: 2 additions & 3 deletions examples/images/sample-myip-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "myip-web-api",
"version": "0.0.1",
"version": "0.0.2",
"description": "CICD sample app API on AWS Lambda",
"main": "index.js",
"scripts": {
Expand All @@ -20,7 +20,6 @@
"chai": "^4.2.0",
"lambda-local": "^1.6.3",
"mocha": "^6.2.0",
"execa": "^2.0.4",
"node-fetch": "^2.6.0"
"execa": "^2.0.4"
}
}
5 changes: 2 additions & 3 deletions examples/images/sample-myip-infrastructure/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "myip-infrastructure",
"version": "0.0.1",
"version": "0.0.2",
"description": "sample app infrastructure on AWS Lambda",
"main": "index.js",
"scripts": {
Expand All @@ -18,7 +18,6 @@
"chai": "^4.2.0",
"lambda-local": "^1.6.3",
"mocha": "^6.2.0",
"execa": "^2.0.4",
"node-fetch": "^2.6.0"
"execa": "^2.0.4"
}
}
5 changes: 1 addition & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
"packages/*"
],
"version": "5.3.0"
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"packages/*"
],
"scripts": {
"bootstrap": "lerna bootstrap",
"bootstrap": "yarn install",
"test": "lerna run prepublishOnly",
"build": "lerna run build",
"buildChanged": "lerna run build --since $(./scripts/base-commit.sh) --include-dependencies --stream"
Expand All @@ -23,8 +23,8 @@
},
"homepage": "https://github.com/ShepherdOrg/shepherd#readme",
"devDependencies": {
"lerna": "^3.18.5",
"lerna-update-wizard": "^0.17.8",
"lerna": "^8.2.4",
"lerna-update-wizard": "^1.1.2",
"prettier": "^1.18.2"
}
}
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shepherdorg/cli",
"version": "5.3.2",
"version": "5.3.3",
"description": "Command line interfaces for Shepherd",
"keywords": [],
"author": "Guðlaugur S. Egilsson <gulli@kolibri.is>",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@shepherdorg/deployer": "^5.3.2",
"@shepherdorg/docker-image-metadata-loader": "^5.2.0",
"@shepherdorg/docker-image-metadata-loader": "^6.0.0",
"@shepherdorg/metadata": "^5.2.0",
"@shepherdorg/versionist": "^5.2.1",
"js-yaml": "^3.13.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/deployer/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "@shepherdorg/deployer",
"version": "5.3.2",
"version": "5.3.3",
"description": "Deployer application",
"main": "dist/shepherd.js",
"engines": {
"node": ">=8"
},
"dependencies": {
"@shepherdorg/docker-image-metadata-loader": "^5.2.0",
"@shepherdorg/docker-image-metadata-loader": "^6.0.0",
"@shepherdorg/filestore-backend": "^5.2.0",
"@shepherdorg/hbs-template": "^5.1.0",
"@shepherdorg/metadata": "^5.2.0",
"@shepherdorg/nano-inject": "^5.1.0",
"@shepherdorg/postgres-backend": "^5.3.2",
"@shepherdorg/state-store": "^5.2.0",
"@shepherdorg/ts-exec": "^5.2.0",
"@shepherdorg/ui-push": "^5.2.0",
"@shepherdorg/ui-push": "^6.0.0",
"@types/diff": "^4.0.2",
"@types/js-yaml": "^3.12.1",
"array-flat-polyfill": "^1.0.1",
Expand Down
6 changes: 2 additions & 4 deletions packages/docker-image-metadata-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shepherdorg/docker-image-metadata-loader",
"version": "5.2.0",
"version": "6.0.0",
"description": "Retrieve docker image metadata efficiently from (private) docker registry, or alternatively by using docker pull and inspect",
"keywords": [
"docker",
Expand Down Expand Up @@ -41,9 +41,7 @@
},
"dependencies": {
"@shepherdorg/ts-exec": "^5.2.0",
"lodash": "^4.17.15",
"request": "^2.88.2",
"request-promise": "^4.2.5"
"lodash": "^4.17.15"
},
"devDependencies": {
"@types/chai": "4.2.11",
Expand Down
106 changes: 75 additions & 31 deletions packages/docker-image-metadata-loader/src/registry-metadata-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as request from "request-promise"
import * as https from "https"
import * as http from "http"
import { URL } from "url"

export type TImageWithTags = {
name: string
Expand Down Expand Up @@ -40,8 +42,21 @@ export interface IRetrieveDockerImageLabels {

}

export type THttpResponse = {
status: number
body: string
}

export type THttpGetOptions = {
url: string
headers?: { [key: string]: string }
ca?: string
}

export type THttpGet = (options: THttpGetOptions) => Promise<THttpResponse>

export type TRegistryClientDependencies = {
request: any
httpGet: THttpGet
}

export type TRegistryClientOptions = {
Expand All @@ -54,8 +69,50 @@ export type TRegistryClientOptions = {
ca?: string
}

const defaultHttpGet: THttpGet = ({ url, headers, ca }) => {
const parsed = new URL(url)
const isHttps = parsed.protocol === "https:"
const lib = isHttps ? https : http
const requestOptions: https.RequestOptions = {
method: "GET",
hostname: parsed.hostname,
port: parsed.port || (isHttps ? 443 : 80),
path: `${parsed.pathname}${parsed.search}`,
headers,
}
if (isHttps && ca) {
requestOptions.ca = ca
}
return new Promise((resolve, reject) => {
const req = lib.request(requestOptions, res => {
const chunks: Buffer[] = []
res.on("data", chunk => chunks.push(Buffer.from(chunk)))
res.on("end", () => {
resolve({
status: res.statusCode || 0,
body: Buffer.concat(chunks).toString("utf8"),
})
})
res.on("error", reject)
})
req.on("error", reject)
req.end()
})
}

const defaultDependencies: TRegistryClientDependencies = {
request: request,
httpGet: defaultHttpGet,
}

class RegistryRequestError extends Error {
statusCode: number
error: string

constructor(statusCode: number, body: string) {
super(`${statusCode}: ${body}`)
this.statusCode = statusCode
this.error = body
}
}


Expand All @@ -68,38 +125,25 @@ export function createDockerRegistryClient(
return image.slice(len, image.length)
}

function addCertificateOptions(requestOptions) {
if (options.ca) {
return {
...requestOptions,
ca: options.ca,
}
} else {
return requestOptions
function buildHeaders(): { [key: string]: string } | undefined {
if (!options.authorization) {
return undefined
}
}

function addAuthorization(request: any) {
if (options.authorization) {
return {
...request,
headers: {
"Authorization":
`${options.authorization.type} ${options.authorization.token}`,
},
}
} else{
return request
return {
Authorization: `${options.authorization.type} ${options.authorization.token}`,
}
}

function getFromDockerRegistry(ApiUrl: string) {
let requestOptions = addCertificateOptions(addAuthorization({
method: "GET",
url: ApiUrl,
},
))
return injected.request(requestOptions)
async function getFromDockerRegistry(apiUrl: string): Promise<string> {
const response = await injected.httpGet({
url: apiUrl,
headers: buildHeaders(),
ca: options.ca,
})
if (response.status < 200 || response.status >= 300) {
throw new RegistryRequestError(response.status, response.body)
}
return response.body
}

function getImageManifest(
Expand Down
3 changes: 1 addition & 2 deletions packages/ui-push/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shepherdorg/ui-push",
"version": "5.2.0",
"version": "6.0.0",
"description": "Push information about deployments to Shepherd UI",
"types": "dist/upload.d.ts",
"main": "dist/upload.js",
Expand All @@ -18,7 +18,6 @@
"license": "ISC",
"dependencies": {
"@shepherdorg/metadata": "^5.2.0",
"@shepherdorg/ui-graphql-client": "^3.3.0",
"add": "^2.0.6"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-push/src/mapDeploymentInfoToUI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai"
import { getValidHerdDeployerMetadata, getValidHerdK8sMetadata } from "./testdata/testdata"
import { DeploymentUIInfo, mapToUiVersion } from "./mapDeploymentInfoToUI"
import { Deployment, DeploymentVersion } from "@shepherdorg/ui-graphql-client"
import { Deployment, DeploymentVersion } from "./ui-graphql-client"


describe("mapping", function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-push/src/mapDeploymentInfoToUI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isHerdDeployerMetadata, isHerdK8sMetadata, THerdDeployerMetadata, THerdK8sMetadata } from "./temptypes"
import { TDeployerRole, TDeploymentType } from "@shepherdorg/metadata"
import { DeploymentVersion, Deployment } from "@shepherdorg/ui-graphql-client"
import { DeploymentVersion, Deployment } from "./ui-graphql-client"

import * as yaml from "js-yaml"
import path from "path"
Expand Down
Loading