Commit 8f775e73 authored by Tristram Gräbener's avatar Tristram Gräbener

Déployer sur gitlab pages

Au lieu de s’embêter avec des choses compliquées chez nous
parent 146f29a8
image: publysher/hugo
html:
stage: build
pages:
script:
- hugo
- echo -n $CI_BUILD_ID > public/.CI_BUILD_ID
- make build
artifacts:
paths:
- public/*
expire_in: 1 week
deploy-review:
image: appropriate/curl
stage: deploy
script:
- curl --fail "$DEPLOY_URL/?secret=$SECRET&CI_BUILD_ID=`cat public/.CI_BUILD_ID`&CI_PROJECT_URL=$CI_PROJECT_URL&CI_PIPELINE_ID=$CI_PIPELINE_ID"
environment:
name: review/$CI_PIPELINE_ID
url: http://$PUBLIC_URL/$CI_PIPELINE_ID/public
- public
only:
- master
......@@ -4,9 +4,7 @@ run: ## Runs a webserver that updates on changes
hugo serve
clean: ## Deletes all the generates files
rm -r ./public
deploy: build ## Deploy the website in production
./deploy.sh
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: build run clean deploy help
.PHONY: build run clean help
#!/usr/bin/env bash
set -e
WWW_HOST="[2001:41d0:2:a420:138::2]"
WWW_PATH="/var/www/default/"
read -p "About to deploy. Are you sure? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "Aborting"
exit 1
fi
set -x
rsync --perms --chmod=a+r -r -v public/ $WWW_HOST:$WWW_PATH
import http.server, socketserver
import requests, io, os
import logging
from urllib.parse import urlparse, parse_qs
from zipfile import ZipFile
from daemonize import Daemonize
pid = "/tmp/www-deploy.pid"
uid = os.getenv("WWW_DEPLOY_UID")
logger = logging.getLogger(__name__)
fh = logging.FileHandler("www-deploy", "w")
logger.addHandler(fh)
logger.setLevel(logging.INFO)
keep_fds = [fh.stream.fileno()]
PORT = 8005
SECRET = os.getenv("WWW_DEPLOY_SECRET")
PATH = "{CI_PROJECT_URL}/builds/{CI_BUILD_ID}/artifacts/download"
DEST = os.getenv("WWW_DEPLOY_PATH") + "/{}"
class Handler(http.server.SimpleHTTPRequestHandler):
def do_GET(s):
try:
params = parse_qs(urlparse(s.path).query)
logger.info("Requested path: {}".format(s.path))
if 'secret' in params and params['secret'][0] == SECRET:
url = PATH.format(CI_PROJECT_URL = params['CI_PROJECT_URL'][0], CI_BUILD_ID = params['CI_BUILD_ID'][0])
logger.info("Fetching file {}".format(url))
file = requests.get(url)
with ZipFile(io.BytesIO(file.content)) as zip:
destination = DEST.format(params['CI_PIPELINE_ID'][0])
logger.info("Extracting the files into {}".format(destination))
zip.extractall(destination)
logger.info("done !")
s.send_response(200)
s.end_headers()
else:
logger.warn("403: Access denied")
s.send_error(403)
s.end_headers()
except Exception as e:
logger.error('Error: {}'.format(e))
s.send_error(500)
s.end_headers()
def main():
httpd = socketserver.TCPServer(("", PORT), Handler)
logger.info("serving at port", PORT)
httpd.serve_forever()
daemon = Daemonize(app="www-deploy", pid=pid, action=main, user=uid, keep_fds=keep_fds, logger=logger, verbose=True)
logger.info("Starting the daemon")
daemon.start()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment