init
This commit is contained in:
parent
eadbb15556
commit
70eaa5205a
2
05-spawn-fcgi.sh
Normal file
2
05-spawn-fcgi.sh
Normal file
@ -0,0 +1,2 @@
|
||||
find /usr/share/nginx/html -type f -iname "*.sh" -exec chmod +x {} \;
|
||||
/usr/bin/spawn-fcgi -s /var/run/fcgiwrap.socket -M 766 /usr/bin/fcgiwrap
|
||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM nginx:alpine
|
||||
|
||||
RUN apk add fcgiwrap spawn-fcgi bash
|
||||
|
||||
COPY ./05-spawn-fcgi.sh /docker-entrypoint.d/05-spawn-fcgi.sh
|
||||
|
||||
RUN chmod +x /docker-entrypoint.d/05-spawn-fcgi.sh
|
||||
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
33
default.conf
Normal file
33
default.conf
Normal file
@ -0,0 +1,33 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name localhost;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
location / {
|
||||
index index.html index.htm;
|
||||
try_files $uri $uri/ /index.html =404;
|
||||
}
|
||||
|
||||
# added example, any shell script in content root will be executable
|
||||
location ~ \.sh$ {
|
||||
gzip off;
|
||||
fastcgi_pass unix:/var/run/fcgiwrap.socket;
|
||||
include /etc/nginx/fastcgi_params;
|
||||
}
|
||||
|
||||
location ~ ^/azure/(.+)/notify$ {
|
||||
gzip off;
|
||||
fastcgi_pass unix:/var/run/fcgiwrap.socket;
|
||||
include /etc/nginx/fastcgi_params;
|
||||
fastcgi_param PROJECT $1;
|
||||
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/azure.sh;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
|
||||
}
|
||||
19
docker-compose.yml
Normal file
19
docker-compose.yml
Normal file
@ -0,0 +1,19 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
|
||||
# https://mac-blog.org.ua/docker-nginx-shell-script/
|
||||
# chmod +x html/*.sh
|
||||
|
||||
nginx-bash:
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: Dockerfile
|
||||
image: nginx-bash
|
||||
container_name: nginx-bash
|
||||
restart: always
|
||||
ports:
|
||||
- 8081:80
|
||||
volumes:
|
||||
- ./html:/usr/share/nginx/html
|
||||
- ./default.conf:/etc/nginx/conf.d/default.conf
|
||||
19
html/50x.html
Normal file
19
html/50x.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Error</title>
|
||||
<style>
|
||||
html { color-scheme: light dark; }
|
||||
body { width: 35em; margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>An error occurred.</h1>
|
||||
<p>Sorry, the page you are looking for is currently unavailable.<br/>
|
||||
Please try again later.</p>
|
||||
<p>If you are the system administrator of this resource then you should check
|
||||
the error log for details.</p>
|
||||
<p><em>Faithfully yours, nginx.</em></p>
|
||||
</body>
|
||||
</html>
|
||||
146
html/azure.sh
Executable file
146
html/azure.sh
Executable file
@ -0,0 +1,146 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo 'Content-Type: text/plain'
|
||||
echo ''
|
||||
# echo "PROJECT: $PROJECT"
|
||||
|
||||
object () {
|
||||
# e.g account
|
||||
kind=$1
|
||||
|
||||
# e.g leandroAccount
|
||||
self=$2
|
||||
|
||||
shift
|
||||
shift
|
||||
|
||||
# iterates over the remaining args
|
||||
for arg in "$@"; do
|
||||
# e.g name=Leandro becomes ARG_KEY=name ARG_VALUE=Leandro
|
||||
read ARG_KEY ARG_VALUE <<< $(echo "$arg" | sed -E "s/(\w+)=(.*?)/\1 \2/")
|
||||
|
||||
if [[ ! -z "$ARG_KEY" ]] && [[ ! -z "$ARG_VALUE" ]]; then
|
||||
# declare the object's state!!!!
|
||||
# e.g export leandroAccount_balance=100
|
||||
export ${self}_$ARG_KEY="$ARG_VALUE"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
notify () {
|
||||
for i in `seq 1 30`;
|
||||
do
|
||||
local RESPONSE_HTTP_CODE=$(curl --max-time 5 -s -o /dev/null -i -w "%{http_code}" -X POST -H "Authorization: Bearer ${1}" -d "message=${3}" "https://notify-api.line.me/api/notify")
|
||||
[[ "${RESPONSE_HTTP_CODE}" == "200" ]] && break
|
||||
sleep 2
|
||||
done
|
||||
curl -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"$(echo ${3}| sed 's/%0A/\\n/g')\"}" https://discord.com/api/webhooks/${2}
|
||||
}
|
||||
|
||||
cicd () {
|
||||
local LINE_TOKEN=$1
|
||||
local DISCORD_TOKEN=$2
|
||||
local repoNameOrigin=$4
|
||||
local branchName=$5
|
||||
local BUILD_NUMBER=$6
|
||||
local buildVersion=$7
|
||||
local GIT_COMMIT=$8
|
||||
local JOB_URL=$9
|
||||
local BUILD_URL=${10}
|
||||
|
||||
case "$3" in
|
||||
"success")
|
||||
local MESSAGE_OPTION="✅✅✅✅✅%0A*CI DONE*"
|
||||
;;
|
||||
"unstable")
|
||||
local MESSAGE_OPTION="💥💥💥💥💥💥%0A*CI Unstable*"
|
||||
;;
|
||||
"failure")
|
||||
local MESSAGE_OPTION="🔥🔥🔥🔥🔥🔥%0A*CI Fail*"
|
||||
;;
|
||||
esac
|
||||
|
||||
notify ${LINE_TOKEN} ${DISCORD_TOKEN} "${MESSAGE_OPTION}%0ARepositories: ${repoNameOrigin}%0ABranch: ${branchName}%0ABuild Number: ${BUILD_NUMBER}%0AImage Tag: ${buildVersion}%0ACommit ID: ${GIT_COMMIT}%0AJob URL: ${JOB_URL}%0ABuild Log: ${BUILD_URL}console"
|
||||
}
|
||||
|
||||
pod () {
|
||||
local LINE_TOKEN=$1
|
||||
local DISCORD_TOKEN=$2
|
||||
local POD_NAME=$4
|
||||
local POD_IP=$5
|
||||
local IMAGE_TAG=$6
|
||||
local NODE=$7
|
||||
case "$3" in
|
||||
"start")
|
||||
local MESSAGE_OPTION="🔆🟢🔆🟢🔆🟢🔆 Service UP"
|
||||
;;
|
||||
"stop")
|
||||
local MESSAGE_OPTION="☠️🔴☠️🔴☠️🔴☠️ Service DOWN"
|
||||
;;
|
||||
esac
|
||||
notify ${LINE_TOKEN} ${DISCORD_TOKEN} "${MESSAGE_OPTION}%0APod NAME: ${POD_NAME}%0APod IP: ${POD_IP}%0AImage Tag: ${IMAGE_TAG}%0ANode: ${NODE}"
|
||||
}
|
||||
|
||||
networkOutbound () {
|
||||
local LINE_TOKEN=$1
|
||||
local DISCORD_TOKEN=$2
|
||||
local DURATION_MIN=$3
|
||||
local DURATION_SEC=$4
|
||||
local NOTIFY_RESPONSE=$(echo $5 | sed 's/-ONLINE/ ✅✅✅✅✅✅/g;s/-OFFLINE/ 🔥🔥🔥🔥🔥🔥/g;s/-:-/ : /g;s/-/ /g;')
|
||||
notify ${LINE_TOKEN} ${DISCORD_TOKEN} "${DURATION_MIN} min ${DURATION_SEC} sec${NOTIFY_RESPONSE}"
|
||||
}
|
||||
|
||||
action () {
|
||||
local LINE_TOKEN=$(eval echo \${${PROJECT}_line_${HTTP_ACTION}})
|
||||
local DISCORD_TOKEN=$(eval echo \${${PROJECT}_discord_${HTTP_ACTION}})
|
||||
case "${HTTP_ACTION}" in
|
||||
"cicd")
|
||||
cicd ${LINE_TOKEN} ${DISCORD_TOKEN} ${HTTP_ACTIONVAL} ${HTTP_REPO} ${HTTP_BRANCH} ${HTTP_BUILDNUM} ${HTTP_BUILDVER} ${HTTP_COMMIT} ${HTTP_JOBURL} ${HTTP_BUILDURL}
|
||||
;;
|
||||
"pod")
|
||||
pod ${LINE_TOKEN} ${DISCORD_TOKEN} ${HTTP_ACTIONVAL} ${HTTP_PODNAME} ${HTTP_PODIP} ${HTTP_IMAGETAG} ${HTTP_NODE}
|
||||
;;
|
||||
"networkOutbound")
|
||||
networkOutbound ${LINE_TOKEN} ${DISCORD_TOKEN} ${HTTP_DURATIONMIN} ${HTTP_DURATIONSEC} ${HTTP_NOTIFYRESPONSE}
|
||||
;;
|
||||
*)
|
||||
echo '{"status":404,"message":"action type not found"}'
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "${PROJECT}" in
|
||||
"clm")
|
||||
object lineToken \
|
||||
${PROJECT}_line \
|
||||
cicd=ZcjlGQUzDqJXHSuh1GQACy6dDGMj32CdMW0MLwwA9da \
|
||||
pod=ZcjlGQUzDqJXHSuh1GQACy6dDGMj32CdMW0MLwwA9da \
|
||||
networkOutbound=ZcjlGQUzDqJXHSuh1GQACy6dDGMj32CdMW0MLwwA9da
|
||||
object discordToken \
|
||||
${PROJECT}_discord \
|
||||
cicd=1270450815580111043/29nP43fgoajLtAHiSbRxRdPjgeE3i-4j4gw5ND4s3mzOsnHjOIeKZS2aZGwlMVkusmta \
|
||||
pod=1270450815580111043/29nP43fgoajLtAHiSbRxRdPjgeE3i-4j4gw5ND4s3mzOsnHjOIeKZS2aZGwlMVkusmta \
|
||||
networkOutbound=1270450815580111043/29nP43fgoajLtAHiSbRxRdPjgeE3i-4j4gw5ND4s3mzOsnHjOIeKZS2aZGwlMVkusmta
|
||||
action
|
||||
;;
|
||||
"ncs")
|
||||
object lineToken \
|
||||
${PROJECT}_line \
|
||||
cicd=ZcjlGQUzDqJXHSuh1GQACy6dDGMj32CdMW0MLwwA9da \
|
||||
pod=ZcjlGQUzDqJXHSuh1GQACy6dDGMj32CdMW0MLwwA9da \
|
||||
networkOutbound=ZcjlGQUzDqJXHSuh1GQACy6dDGMj32CdMW0MLwwA9da
|
||||
object discordToken \
|
||||
${PROJECT}_discord \
|
||||
cicd=1270450815580111043/29nP43fgoajLtAHiSbRxRdPjgeE3i-4j4gw5ND4s3mzOsnHjOIeKZS2aZGwlMVkusmta \
|
||||
pod=1270450815580111043/29nP43fgoajLtAHiSbRxRdPjgeE3i-4j4gw5ND4s3mzOsnHjOIeKZS2aZGwlMVkusmta \
|
||||
networkOutbound=1270450815580111043/29nP43fgoajLtAHiSbRxRdPjgeE3i-4j4gw5ND4s3mzOsnHjOIeKZS2aZGwlMVkusmta
|
||||
action
|
||||
;;
|
||||
*)
|
||||
echo '{"status":404,"message":"project not found"}'
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
echo '{"status":200,"message":"ok"}'
|
||||
11
html/demo.sh
Executable file
11
html/demo.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo 'Content-Type: text/plain'
|
||||
echo ''
|
||||
echo 'Hello, world!'
|
||||
echo 'KLxHunter'
|
||||
echo 'Environment:'
|
||||
env
|
||||
|
||||
# notify_token=ZcjlGQUzDqJXHSuh1GQACy6dDGMj32CdMW0MLwwA9da
|
||||
# curl -X POST -H "Authorization: Bearer ${notify_token}" -F "message=return of the mount hua sect มาแว๊ววว" https://notify-api.line.me/api/notify
|
||||
22
html/index.html
Normal file
22
html/index.html
Normal file
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to nginx!</title>
|
||||
<style>
|
||||
html { color-scheme: light dark; }
|
||||
body { width: 35em; margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to nginx!</h1>
|
||||
<p>If you see this page, the nginx web server is successfully installed and
|
||||
working. Further configuration is required.</p>
|
||||
|
||||
<p>For online documentation and support please refer to
|
||||
<a href="http://nginx.org/">nginx.org</a>.<br/>
|
||||
Commercial support is available at
|
||||
<a href="http://nginx.com/">nginx.com</a>.</p>
|
||||
<p><em>Thank you for using nginx.</em></p>
|
||||
</body>
|
||||
</html>
|
||||
39
test.sh
Normal file
39
test.sh
Normal file
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
Object () {
|
||||
# e.g account
|
||||
kind=$1
|
||||
|
||||
# e.g leandroAccount
|
||||
self=$2
|
||||
|
||||
shift
|
||||
shift
|
||||
|
||||
# iterates over the remaining args
|
||||
for arg in "$@"; do
|
||||
# e.g name=Leandro becomes ARG_KEY=name ARG_VALUE=Leandro
|
||||
read ARG_KEY ARG_VALUE <<< $(echo "$arg" | sed -E "s/(\w+)=(.*?)/\1 \2/")
|
||||
|
||||
if [[ ! -z "$ARG_KEY" ]] && [[ ! -z "$ARG_VALUE" ]]; then
|
||||
# declare the object's state!!!!
|
||||
# e.g export leandroAccount_balance=100
|
||||
export ${self}_$ARG_KEY="$ARG_VALUE"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
Object account leandroAccount name=Leandro balance=500
|
||||
|
||||
echo $leandroAccount_name # prints Leandro
|
||||
echo $leandroAccount_balance # prints 500
|
||||
|
||||
Object account carlosAccount name=Carlitos balance=800
|
||||
|
||||
echo $carlosAccount_name # prints Carlitos
|
||||
echo $carlosAccount_balance # prints 800
|
||||
|
||||
# curl -H "ACTION: cicd" -H "ACTIONVAL: success" -H "REPO: complaint-backend-complaint" -H "BRANCH: develop" -H "BUILDNUM: 478" -H "BUILDVER: develop-0.0.478" -H "COMMIT: 3634e06b2c7b93cf146530917a93a30de25943e0" -H "JOBURL: https://jenkins-back.devopsnonprd.vayuktbcs:8080/job/complaint/job/backend/job/complaint-backend-complaint/job/develop/" -H "BUILDURL: https://jenkins-back.devopsnonprd.vayuktbcs:8080/job/complaint/job/backend/job/complaint-backend-complaint/job/develop/478/" -H "Content-Type: application/json" localhost:8081/azure/clm/notify
|
||||
|
||||
# curl -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"✅✅✅✅✅\n*CI DONE*\nRepositories: ${repoNameOrigin}\nBranch: ${branchName}\nBuild Number: ${BUILD_NUMBER}\nImage Tag: ${buildVersion}\nCommit ID: ${GIT_COMMIT}\nJob URL: ${JOB_URL}\nBuild Log: ${BUILD_URL}console\"}" https://discord.com/api/webhooks/1270450815580111043/29nP43fgoajLtAHiSbRxRdPjgeE3i-4j4gw5ND4s3mzOsnHjOIeKZS2aZGwlMVkusmta
|
||||
|
||||
Loading…
Reference in New Issue
Block a user