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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
.build/
build/
package-lock.json
dist/
.testrun/
Expand Down
3 changes: 1 addition & 2 deletions packages/deployer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@
"typescript": "^3.7.3"
},
"scripts": {
"build-test-images": "cd src/integratedtest/testimages && ./build-test-images.sh",
"start-postgres": "docker run --rm --name postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres",
"kill-postgres": "docker stop postgres",
"specs": "mocha --exit --require ts-node/register --recursive 'src/**/*.spec.ts'",
"coverage": "TS_NODE_COMPILER_OPTIONS='{\"removeComments\":false}' nyc mocha --require ts-node/register --require source-map-support/register --recursive 'src/**/*.spec.ts'",
"tdd": "mocha --exit -R dot --require ts-node/register --recursive --watch-extensions ts --watch 'src/**/*.spec.ts'",
"integratedtest": "yarn build && yarn build-test-images && mocha --exit --recursive 'dist/integratedtest/**/*.integratedtest.js'",
"integratedtest": "yarn build && mocha --exit --recursive 'dist/integratedtest/**/*.integratedtest.js'",
"compile-in-background": "tsc -w > /dev/null &",
"itdd": "npm run compile-in-background && mocha --exit --require ts-node/register --recursive --watch-extensions ts,js,sh --watch 'src/**/*.integratedtest.ts'",
"test": "yarn specs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { TK8sDeploymentPlan, TShepherdMetadata } from "../../deployment-types"
import { shepherdOptions } from "../../shepherd-options"
import { kubeSupportedExtensions } from "./kube-supported-extensions"
import * as path from "path"
import { expandEnvAndMustacheVariablesInFile } from "./kubectl-deployment-action-factory"
import { expandTemplate } from "@shepherdorg/hbs-template"
import * as chalk from "chalk"

export function expandTemplatesInImageArchiveFiles(imageInformation: TShepherdMetadata & { dockerLabels: { [p: string]: any } }, plan: TK8sDeploymentPlan) {
export function expandTemplatesInImageArchiveFiles(
imageInformation: TShepherdMetadata & { dockerLabels: { [p: string]: any } },
plan: TK8sDeploymentPlan
) {
if (shepherdOptions.testRunMode()) {
process.env.TPL_DOCKER_IMAGE = "fixed-for-testing-purposes"
} else {
process.env.TPL_DOCKER_IMAGE =
imageInformation.imageDeclaration.image + ":" + imageInformation.imageDeclaration.imagetag

}

if (!plan.files) {
Expand All @@ -26,10 +28,12 @@ export function expandTemplatesInImageArchiveFiles(imageInformation: TShepherdMe

try {
if (archivedFile.content) {
archivedFile.content = expandEnvAndMustacheVariablesInFile(archivedFile.content)
archivedFile.content = expandTemplate(archivedFile.content)
}
} catch (e) {
let message = `When expanding templates in ${chalk.blueBright(imageInformation.imageDeclaration.image)} ${chalk.red(fileName)}:\n${e.message}`
let message = `When expanding templates in ${chalk.blueBright(
imageInformation.imageDeclaration.image
)} ${chalk.red(fileName)}:\n${e.message}`
throw new Error(message)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { newProgrammerOops, Oops } from "oops-error"
import { expandEnv } from "../../template/expandenv"
import { processLine } from "../../template/base64-env-subst"
import { expandTemplate } from "@shepherdorg/hbs-template"
import * as path from "path"
import { writeFile } from "../../helpers/promisified"
import { TK8sPartialDescriptor } from "./k8s-document-types"
Expand Down Expand Up @@ -58,10 +57,6 @@ function expandEnvVariables(lines: string[]) {
return lines.join("\n")
}

export function expandEnvAndMustacheVariablesInFile(deploymentFileDescriptorContent: string) {
return expandTemplate(expandEnvVariables(deploymentFileDescriptorContent.split("\n")))
}

export interface ICreateKubectlDeploymentAction {
executeKubectlDeploymentAction: (
thisIsMe: IKubectlDeployAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe("Docker image plan loader", function() {
})
})

describe("missing env variable", function() {
describe("missing env variable, #2", function() {
let loadError: Error
before(function() {
delete process.env.EXPORT1
Expand Down Expand Up @@ -410,7 +410,7 @@ describe("Docker image plan loader", function() {
})
})

describe("missing env variable", function() {
xdescribe("missing env variable, $ is now obsolete", function() {
let loadError: Error
before(async function() {
delete process.env.EXPORT1
Expand All @@ -436,7 +436,7 @@ describe("Docker image plan loader", function() {
})
})

describe("missing env variable for base64 decoding", function() {
xdescribe("missing env variable for base64 decoding, $ variable is obsolete, redesign this test", function() {
let loadError: Error
before(async function() {
process.env.EXPORT1 = "qwerty"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as fs from "fs"
import * as path from "path"
import { emptyArray } from "../../helpers/ts-functions"
import {
expandEnvAndMustacheVariablesInFile,
ICreateKubectlDeploymentAction,
} from "../../deployment-actions/kubectl-action/kubectl-deployment-action-factory"
import { expandTemplate } from "@shepherdorg/hbs-template"
import { ICreateKubectlDeploymentAction } from "../../deployment-actions/kubectl-action/kubectl-deployment-action-factory"
import {
IK8sDirDeploymentAction,
IKubectlDeployAction,
Expand Down Expand Up @@ -136,7 +134,7 @@ export function createFolderActionFactory(
const kubeDeploymentRelativePath = path.relative(initialDir, resolvedPath)

try {
data = expandEnvAndMustacheVariablesInFile(data)
data = expandTemplate(data)
const deploymentAction: IKubectlDeployAction = injected.kubectlDeploymentActionFactory.createKubectlDeployAction(
kubeDeploymentRelativePath,
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ describe("running shepherd", function() {
firstRun = script
.execute(shepherdTestHarness, [], {
env: _.extend(testEnv, process.env),
// stdoutLineHandler: (line: string) => {
// console.log(`DEBUG ${line}`)
// },
})
.done(function(_stdout) {
// console.log(`stdout`, stdout)
Expand Down
28 changes: 15 additions & 13 deletions packages/deployer/src/test-tools/script-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface TScriptTestExecution {
expectExitCode: (expectedExitCode: number) => TScriptTestExecution
done: (callback: FExecutionCallback) => TScriptTestExecution
checkExpectations: () => void
unexpectedError?: string
}

function emptyArray<T>(): Array<T> {
Expand All @@ -113,7 +114,6 @@ export type TExecuteOptions = {
}

export default {
// Pass in debug=true if you want to see output of subject under test.
execute: function(command: string, args: string[], options: TExecuteOptions) {
options.env = extend({}, options.env, { PATH: process.env.PATH })

Expand All @@ -132,19 +132,18 @@ export default {
execution.checkExpectations()
execution.callback && execution.callback(execError.stdout)
} else {
console.error("Process error in test, error code:", execError.code, " stderr:", execError.stderr)
expect.fail(
console.error("Process error in test", execError)
execution.unexpectedError =
"Error invoking : " +
command +
" with arguments " +
JSON.stringify(args) +
"\nStdout: \n" +
execError.stdout +
"\nError output:\n" +
execError.stderr +
"\n. ErrorCode:" +
execError.code
)
command +
" with arguments " +
JSON.stringify(args) +
"\nStdout: \n" +
execError.stdout +
"\nError output:\n" +
execError.stderr +
"\n. ErrorCode:" +
execError.code
}
})

Expand Down Expand Up @@ -220,6 +219,9 @@ export default {
return execution
},
checkExpectations() {
if (execution.unexpectedError) {
expect.fail(execution.unexpectedError)
}
if (execution.expectedExitCode) {
expect(execution.actualExitCode).to.equal(execution.expectedExitCode, "Process exit code")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
imagePullSecrets:
- name: registry-pull-secret
containers:
- image: ${TPL_DOCKER_IMAGE}
- image: {{TPL_DOCKER_IMAGE}}
name: www-icelandair-com
resources:
limits:
Expand All @@ -43,7 +43,7 @@ spec:
- name: RUNTIME_ENV2
valueFrom:
configMapKeyRef:
name: ${EXPORT2}
name: {{EXPORT2}}
key: ENV
- image: DOCKER_IMAGE_SSR
name: www-icelandair-com-ssr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
imagePullSecrets:
- name: registry-pull-secret
containers:
- image: ${TPL_DOCKER_IMAGE}
- image: {{TPL_DOCKER_IMAGE}}
secondaryImage: {{{ TPL_DOCKER_IMAGE }}}
name: www-icelandair-com
resources:
Expand Down Expand Up @@ -44,7 +44,7 @@ spec:
- name: RUNTIME_ENV2
valueFrom:
configMapKeyRef:
name: ${EXPORT2}
name: {{EXPORT2}}
key: ENV
- name: RUNTIME_ENV_3
value: {{BRANCH_NAME}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
labels:
name: www-icelandair-com
subdomain: ${SUB_DOMAIN_PREFIX}beta
topdomain: ${PREFIXED_TOP_DOMAIN_NAME}
subdomain: {{SUB_DOMAIN_PREFIX}}beta
topdomain: {{PREFIXED_TOP_DOMAIN_NAME}}
team: flip
spec:
type: LoadBalancer
Expand All @@ -30,8 +30,8 @@ metadata:
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
labels:
name: www-icelandair-com
subdomain: ${SUB_DOMAIN_PREFIX}beta
topdomain: ${PREFIXED_TOP_DOMAIN_NAME}
subdomain: {{SUB_DOMAIN_PREFIX}}beta
topdomain: {{PREFIXED_TOP_DOMAIN_NAME}}
team: flip
spec:
type: LoadBalancer
Expand Down
1 change: 1 addition & 0 deletions packages/deployer/testbin/test-shepherd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export PATH=$(pwd)/testbin:$(pwd)/bin:${PATH}
if [ -z "${HERDFILE}" ]; then
export HERDFILE="$(pwd)/src/herd-loading/testdata/happypath/herd.yaml"
fi
echo Using HERDFILE: ${HERDFILE}


if [ -z "${DRYRUN_OUTPUT_FOLDER}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion packages/postgres-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"bluebird": "^3.7.0",
"lodash": "^4.17.15",
"pg": "^7.12.1"
"pg": "^8.7.3"
},
"peerDependencies": {
"@shepherdorg/metadata": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/postgres-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PGConnectionConfig } from "./pg-config"

export { PgConfig } from "./pg-config"

import {Client} from "pg"
import { Client } from "pg"

export interface IPostgresStorageBackend extends IStorageBackend {
resetAllDeploymentStates()
Expand Down Expand Up @@ -31,14 +31,14 @@ const StoreClient = (client: Client) => ({
export function PostgresStore(config: PGConnectionConfig): IPostgresStorageBackend {
let client

const ensureDeploymentsTable= async function() {
const ensureDeploymentsTable = async function() {
await client.query(
"CREATE TABLE IF NOT EXISTS deployments (identifier TEXT PRIMARY KEY, data JSONB, lastdeployment TIMESTAMP NOT NULL)",
"CREATE TABLE IF NOT EXISTS deployments (identifier TEXT PRIMARY KEY, data JSONB, lastdeployment TIMESTAMP NOT NULL)"
)
}

return {
async connect() {
async connect() {
client = StoreClient(new Client(config))
await client.connect()
if (config.schema) {
Expand Down
1 change: 1 addition & 0 deletions packages/storage-backend-tester/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default (backendName: string, createBackend: () => IStorageBackend) => {
describe(`${backendName} store backend`, function() {
let store

this.timeout(70000)
beforeEach(function() {
store = createBackend()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bash
THISDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )


set -eao pipefail
unset DOCKER_REGISTRY_HOST
export PATH=$PATH:${THISDIR}/node_modules/.bin
export FORCE_REBUILD=true


echo "Rebuilding test images"
(cd ${THISDIR}/test-migration-image/ && ./build-docker.sh)
(cd ${THISDIR}/test-image && ./build-docker.sh)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
data:
{{SECRET_KEY}}: {{Base64Encode:SECRET_TEXT}}
{{SECRET_KEY}}: {{Base64Encode SECRET_TEXT}}
kind: Secret
metadata:
imagename: DOCKER_IMAGE
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ metadata:
team: flip
data:
whitelist: |-
${Base64Decode:WWW_ICELANDAIR_IP_WHITELIST}
{{Base64Decode WWW_ICELANDAIR_IP_WHITELIST}}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
imagePullSecrets:
- name: registry-pull-secret
containers:
- image: ${TPL_DOCKER_IMAGE}
- image: {{TPL_DOCKER_IMAGE}}
name: www-icelandair-com
resources:
limits:
Expand All @@ -43,7 +43,7 @@ spec:
- name: RUNTIME_ENVIRONMENT
valueFrom:
configMapKeyRef:
name: ${EXPORT1}
name: {{EXPORT1}}
key: ENV
- image: DOCKER_IMAGE_SSR
name: www-icelandair-com-ssr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
labels:
name: www-icelandair-com
subdomain: '${SUB_DOMAIN_PREFIX}beta'
topdomain: ${PREFIXED_TOP_DOMAIN_NAME}
subdomain: '{{SUB_DOMAIN_PREFIX}}beta'
topdomain: {{PREFIXED_TOP_DOMAIN_NAME}}
team: flip
spec:
type: LoadBalancer
Expand All @@ -30,8 +30,8 @@ metadata:
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
labels:
name: www-icelandair-com
subdomain: ${SUB_DOMAIN_PREFIX}beta
topdomain: ${PREFIXED_TOP_DOMAIN_NAME}
subdomain: {{SUB_DOMAIN_PREFIX}}beta
topdomain: {{PREFIXED_TOP_DOMAIN_NAME}}
team: flip
spec:
type: LoadBalancer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
imagePullSecrets:
- name: registry-pull-secret
containers:
- image: ${TPL_DOCKER_IMAGE}
- image: {{TPL_DOCKER_IMAGE}}
name: image2
resources:
limits:
Expand All @@ -43,7 +43,7 @@ spec:
- name: RUNTIME_ENVIRONMENT
valueFrom:
configMapKeyRef:
name: ${EXPORT1}
name: {{EXPORT1}}
key: ENV
- image: DOCKER_IMAGE_SSR
name: image2-ssr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ metadata:
team: flip
data:
whitelist: |-
${Base64Decode:WWW_ICELANDAIR_IP_WHITELIST}
{{Base64Decode WWW_ICELANDAIR_IP_WHITELIST}}
Loading