diff --git a/README.org b/README.org new file mode 100644 index 0000000..189592d --- /dev/null +++ b/README.org @@ -0,0 +1,17 @@ +* Webhooks +** Descripció +Servidor HTTP senzill que escolta peticions per a executar scripts. + +** Variables d'entorn +- WEBHOOK_HOST: Host del servidor de webhook +- WEBHOOK_PORT: Port del servidor de webhook +- CONFIG_FILE: Path al fitxer de configuració + +** Scripts +*** deploy_hugo.sh +Construeix i deploya una web estàtica amb hugo +**** Variables +- GIT_REPO_URL: Url SSH del repositori amb la web +- GIT_SSH_ID_FILE: Clau pública d'accés SSH +- HUGO_PARAMS: Paràmetres extra per a la comanda d'`hugo` +- TARGET_DIR: Directori de destí per construir la pàgina diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..9e80e11 --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,23 @@ +FROM klakegg/hugo:alpine-ci + +# Install git and ssh +RUN apk add --no-cache git openssh + +# Install python/pip +ENV PYTHONUNBUFFERED=1 +RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python +RUN python3 -m ensurepip +RUN pip3 install --no-cache --upgrade pip setuptools + +WORKDIR /app + +# Install requirements +COPY requirements.txt requirements.txt +COPY main.py main.py +RUN pip install -r requirements.txt + +# Add scripts +COPY scripts scripts +RUN chmod +x scripts/*.sh + +CMD python main.py diff --git a/deploy/deploy.sh b/deploy/deploy.sh new file mode 100644 index 0000000..c12f879 --- /dev/null +++ b/deploy/deploy.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +# BUILD +docker build . -f deploy/Dockerfile -t webhooks:latest + +# PUBLISH +docker tag pasta-server marc.sastre.cat/webhooks:latest +docker push marc.sastre.cat/webhooks diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c9bb170 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3" +services: + webhooks: + build: + context: . + dockerfile: deploy/Dockerfile + environment: + CONFIG_FILE: ./config.json + ports: + - "6000:6000" + volumes: + - ./test/config.json:/app/config.json + - /home/marc/.ssh/lajuntament:/app/lajuntament diff --git a/test/deploy.sh b/scripts/deploy_hugo.sh old mode 100755 new mode 100644 similarity index 100% rename from test/deploy.sh rename to scripts/deploy_hugo.sh diff --git a/test/config.json b/test/config.json index 8161cd1..bad8f2a 100644 --- a/test/config.json +++ b/test/config.json @@ -2,10 +2,10 @@ "lajuntament": { "test": { "secret": "elsecret", - "deploy_script": "./test/deploy.sh", + "deploy_script": "./scripts/deploy_hugo.sh", "env": { "GIT_REPO_URL": "ssh://git@git.lajuntament.space:2222/lajuntament/web.git", - "GIT_SSH_ID_FILE": "/home/marc/.ssh/lajuntament.pub" + "GIT_SSH_ID_FILE": "/app/lajuntament" } } }