From 4bc26508920998b6a6e1cde706cf6a65f76d65e1 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 24 Jul 2021 14:45:23 +0200 Subject: [PATCH] ci: add a deploy step using docker-compose docs image is built JIT from Dockerfile. the logic for the compose file is based on the one used in https://git.dotya.ml/dotya.ml/homepage yet the traefik part was not used. --- .drone.yml | 77 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 26 ++++++++++++++++ docker-compose.yml | 21 +++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.drone.yml b/.drone.yml index f052280..c5837e4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -44,6 +44,83 @@ steps: - hugo version - hugo --gc=true --minify +--- +kind: pipeline +type: docker +name: deploy + +platform: + os: linux + arch: amd64 + +trigger: + branch: + - master + event: + exclude: [pull_request, tag] + +environment: + # ref: https://www.docker.com/blog/faster-builds-in-compose-thanks-to-buildkit-support/ + COMPOSE_DOCKER_CLI_BUILD: 1 + DOCKER_BUILDKIT: 1 + +node: + r: main + +depends_on: +- build + +steps: +- name: hugo-extended + pull: if-not-exists + image: immawanderer/fedora-hugo:latest + commands: + - git submodule init + - git submodule update + - hugo version + - hugo --gc=true --minify + +- name: rm-intermediate + pull: if-not-exists + image: immawanderer/fedora-hugo:latest + depends_on: + - hugo-extended + commands: + - rm -rf ./public + +- name: build + pull: always + image: tmaier/docker-compose:latest + depends_on: + - rm-intermediate + volumes: + - name: s + path: /var/run/docker.sock + commands: + - docker-compose build --no-cache + when: + branch: master + status: success + +- name: deploy + pull: always + image: tmaier/docker-compose:latest + depends_on: + - build + volumes: + - name: s + path: /var/run/docker.sock + commands: + - docker-compose up -d --remove-orphans + when: + branch: master + status: success + +volumes: +- name: s + host: + path: /var/run/docker.sock + --- kind: pipeline name: notifications diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..75c7ebb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM immawanderer/fedora-hugo:latest AS hugobuild +RUN mkdir -pv /docs +COPY . /docs + +WORKDIR /docs + +RUN git submodule init \ +&& git submodule update --recursive \ +&& hugo version +RUN hugo --minify --gc=true + +# WORKDIR / + +FROM nginx:mainline-alpine +# COPY --from=hugobuild /home/$(whoami)/public/ /usr/share/nginx/html +COPY --from=hugobuild /docs/public/ /usr/share/nginx/html + +# tripple slash reference +# https://stackoverflow.com/questions/5190966/using-sed-to-insert-tabs/5191165#5191165 +RUN sed -i -e 's/^worker_processes auto;/worker_processes auto;/'\ + -e "/^events {$/ a \\\tmulti_accept on;\n\tuse epoll;"\ + -e "/^http {$/ a \\\tserver_tokens off;\n\tetag off;\n"\ + -e 's/#tcp_nopush/tcp_nopush/'\ + -e "/tcp_nopush/ a \\\ttcp_nodelay on;"\ + -e "s/^ */$(printf '\t')/"\ + /etc/nginx/nginx.conf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..571d8ec --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3' +services: + docs: + build: + context: . + image: docs + networks: + - default + restart: always + ports: + - 127.0.0.1:1315:80 + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + logging: + driver: json-file + options: + max-size: "5m" + max-file: "5" + +networks: + default: