Skip to content

Commit

Permalink
add hello-bad seq
Browse files Browse the repository at this point in the history
  • Loading branch information
karoltylenda committed Jan 30, 2024
1 parent 5d3e464 commit 39d19cf
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 0 deletions.
16 changes: 16 additions & 0 deletions js/hello-bad/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM alpine:latest
ENV SEQUENCER_VERSION=v2.8

RUN apk add --update npm curl jq

COPY . .

RUN npm i @scramjet/cli -g

RUN si seq pack . -o hello.tar.gz

COPY seq.sh /usr/local/bin/seq.sh

RUN chmod u+x /usr/local/bin/seq.sh

ENTRYPOINT [ "/usr/local/bin/seq.sh" ]
72 changes: 72 additions & 0 deletions js/hello-bad/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
pipeline {
agent {
node {
label "docker"
}
}
environment {
base_path = "apps-images/sequencer"
}
stages {
stage("Checkout SCM") {
steps {
checkout scm
}
}
stage("Build Docker Image") {
steps {
script {
dir("${base_path}") {
image = docker.build("apps/sequencer")
}
}
}
}
stage("Publish Docker") {
// Run only in master branch
when {
branch 'main'
}
steps {
script {
dir("${base_path}") {
def version = sh(returnStdout: true, script: "awk -F= '/^ENV SEQUENCER_VERSION/ {print \$2}' Dockerfile").trim()
docker.withRegistry('https://repo.int.scp.ovh', 'docker-repo') {
image.push("${version}")
image.push("latest")
}
}
}
}
}
}
post {
always {
// When successed currentBuild.result is null
script {
if (currentBuild.result == null) {
currentBuild.result = 'SUCCESS'
}
}
echo "Cleaning.."
cleanWs()
}
// Slack Notifications syntax: https://www.jenkins.io/doc/pipeline/steps/slack/
unsuccessful {
script {
// CHANGE_ID is set only for pull requests
if (env.CHANGE_ID) {
slackSend (color: '#FF0000', message: "Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL}) failed.")
}
}
}
fixed {
script {
// CHANGE_ID is set only for pull requests
if (env.CHANGE_ID) {
slackSend (color: '#00FF00', message: "Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL}) back to normal.")
}
}
}
}
}
15 changes: 15 additions & 0 deletions js/hello-bad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# sequencer

Docker image for sequencer builded on top of Alpine base image.

## Build

```bash
docker build --no-cache -t repo.int.scp.ovh/apps/sequencer:v2.9 .
```

## Run

```bash
docker run -ti sequencer:v2.9 127.0.0.1
```
10 changes: 10 additions & 0 deletions js/hello-bad/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { Transform } = require("stream");

module.exports = function(input) {
return input.pipe(new Transform({
encoding: "utf-8",
transform(chunk, _encoding, callback) {
callback(null, `Hello ${chunk}`);
}
}));
};
20 changes: 20 additions & 0 deletions js/hello-bad/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@scramjet/hello-bad",
"version": "0.13.1",
"description":"Sequence that modifies incoming stream of strings by saying Hello",
"main": "app.js",
"author": "Scramjet <open-source@scramjet.org>",
"license": "GPL-3.0",
"scripts": {
"build:refapps": "node ../../scripts/build-all.js",
"postbuild:refapps": "yarn prepack && yarn packseq",
"clean": "rm -rf ./dist .bic_cache",
"prepack": "PACKAGES_DIR=js node ../../scripts/publish.js",
"packseq": "PACKAGES_DIR=js node ../../scripts/packsequence.js"
},
"repository": {
"type": "git",
"url": "https://github.com/scramjetorg/transform-hub.git"
},
"assets": ["name.txt"]
}
49 changes: 49 additions & 0 deletions js/hello-bad/seq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh -x

if [ "$#" -ne 1 ]
then
echo "Usage: ./seq <multimanager.k8s.example.com|127.0.0.1>"
exit 1
fi

echo "Image build from https://github.com/scramjetorg/docker"
mmEndpoint=$1

si -v

si config set log --debug false
si config set log --format json

#get first managerID
manager=$(curl -s http://$mmEndpoint:11000/api/v1/list |jq -r .[0].id)
if [ -z "$manager" ]; then
echo "No manager found";
exit 1
else
echo "manager: $manager"
fi

# get first healthy STH ID
sth=$(curl -s http://$mmEndpoint:11000/api/v1/cpm/$manager/api/v1/list |jq -r '[.[] | select( .healthy == true )][0].id')
if [ -z "$sth" ]; then
echo "No healthy STH found";
exit 1
else
echo "STH: $sth"
fi

#check if seq exists, if true exit script
seq=$(curl -s http://$mmEndpoint:11000/api/v1/cpm/$manager/api/v1/sth/$sth/api/v1/sequences |jq -r .[0].id)
if [ -z "$seq" ] || [[ "$seq" == 'null' ]]; then
echo "No sequence found, continuing.."
else
echo "Found sequence $seq Exit script."
exit 0
fi

#si
si config use apiUrl http://$mmEndpoint:11000/api/v1/cpm/$manager/api/v1/sth/$sth/api/v1 |jq

si config p |jq
si seq pack . -o hello.tar.gz
si seq send hello.tar.gz |jq

0 comments on commit 39d19cf

Please sign in to comment.