add files to create Docker image
This commit is contained in:
parent
0bf1394fa5
commit
c20cb9cb13
|
|
@ -0,0 +1,27 @@
|
|||
# Use the official Python image as the base image
|
||||
FROM python:latest
|
||||
|
||||
# Install Supervisord
|
||||
RUN pip install supervisor flask
|
||||
|
||||
# Copy your Supervisord configuration file into the container
|
||||
COPY supervisord.conf /etc/supervisor/supervisord.conf
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin
|
||||
|
||||
# Create a directory for your Python script
|
||||
WORKDIR /home/githook
|
||||
|
||||
# Copy your Python script into the container
|
||||
COPY githook.py .
|
||||
|
||||
|
||||
# Expose any necessary ports (if your script listens on a specific port)
|
||||
EXPOSE 5000
|
||||
EXPOSE 8080
|
||||
|
||||
WORKDIR /home/
|
||||
|
||||
# Define the command to start Supervisord
|
||||
CMD ["entrypoint.sh"]
|
||||
#CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Check if the REPO_URL environment variable is set
|
||||
if [ -z "$GIT_REPO" ]; then
|
||||
echo "Error: REPO_URL environment variable is not set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set the target directory
|
||||
TARGET_DIR="/home/app"
|
||||
|
||||
# Check if the target directory already exists
|
||||
if [ ! -d "$TARGET_DIR" ]; then
|
||||
# If it doesn't exist, clone the repository
|
||||
git clone "$GIT_REPO" "$TARGET_DIR"
|
||||
else
|
||||
# If it already exists, update the repository
|
||||
cd "$TARGET_DIR" || exit 1
|
||||
git pull origin master
|
||||
fi
|
||||
|
||||
mkdir -p /var/run/supervisor
|
||||
|
||||
# Run your application or desired command
|
||||
cmd="supervisord -c /etc/supervisor/supervisord.conf"
|
||||
$cmd
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
from flask import Flask, request, jsonify
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
path="/home/app"
|
||||
|
||||
@app.route('/githook', methods=['POST'])
|
||||
def githook():
|
||||
try:
|
||||
subprocess.run(['supervisorctl', 'stop', 'app'], check=True)
|
||||
subprocess.run(['git', 'pull'], check=True, cwd=path)
|
||||
subprocess.run(['supervisorctl', 'start', 'app'], check=True)
|
||||
return "", 200
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
[supervisord]
|
||||
nodaemon=true
|
||||
|
||||
[program:githook-server]
|
||||
command=python githook.py
|
||||
directory=/home/githook
|
||||
autostart=true
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/githook.log
|
||||
|
||||
[program:app]
|
||||
command=python app.py
|
||||
directory=/home/app
|
||||
autostart=true
|
||||
autorestart=false
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/app.log
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor/supervisor.sock
|
||||
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor/supervisor.sock
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
Loading…
Reference in New Issue