From 56cd13ce756daaaf688c59891a8e4d4b57f5f9c3 Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Wed, 19 Aug 2020 18:54:44 -0400
Subject: [PATCH] Use GitLab CI to build site

---
 .dockerignore    |  4 ++++
 .gitlab-ci.yml   | 28 ++++++++++++++++++++++++++++
 Dockerfile       |  6 ++++++
 nginx.conf       | 15 +++++++++++++++
 pelicanconf.py   |  4 +++-
 requirements.txt |  3 +++
 6 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 .dockerignore
 create mode 100644 .gitlab-ci.yml
 create mode 100644 Dockerfile
 create mode 100644 nginx.conf

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..b5fec70
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,4 @@
+*
+!output
+!nginx.conf
+!requirements.txt
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..49871c2
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,28 @@
+stages:
+  - build_content
+  - build_image
+
+build_content:
+  stage: build_content
+  image: python:3
+  script:
+    - pip install -r requirements.txt
+    - pelican content -o output -s pelicanconf.py
+  artifacts:
+    paths:
+      - output/
+
+build_image:
+  stage: build_image
+  dependencies:
+    - build_content
+  image:
+    name: gcr.io/kaniko-project/executor:debug
+    entrypoint: [""]
+  variables:
+    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
+  script:
+    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
+    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
+  only:
+   - tags
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..46df403
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,6 @@
+FROM nginx:1.17
+
+RUN rm /etc/nginx/conf.d/default.conf
+
+COPY nginx.conf /etc/nginx/conf.d/ant.sr.conf
+COPY output /opt/ant.sr/html
diff --git a/nginx.conf b/nginx.conf
new file mode 100644
index 0000000..4d50d1f
--- /dev/null
+++ b/nginx.conf
@@ -0,0 +1,15 @@
+server {
+    listen 80;
+    location / {
+        root /opt/ant.sr/html;
+        error_page 404 = @files;
+    }
+    location @files {
+        root /opt/ant.sr/files;
+        error_page 404 = @urlshortener
+    }
+    location @urlshortener {
+        # TODO!
+        return 404;
+    }
+}
diff --git a/pelicanconf.py b/pelicanconf.py
index 686e249..75640fe 100644
--- a/pelicanconf.py
+++ b/pelicanconf.py
@@ -1,11 +1,13 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*- #
 from __future__ import unicode_literals
+import os
+
 
 AUTHOR = 'Anton Sarukhanov'
 SITENAME = 'Anton Sarukhanov'
 SITESUBTITLE = 'Full-Stack Developer'
-# SITEURL = 'https://ant.sr/'
+SITEURL = os.environ.get('SITEURL')
 
 PLUGINS = ['advthumbnailer']
 
diff --git a/requirements.txt b/requirements.txt
index 70ee8c9..93f8cfd 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,6 @@
+wheel
 pelican==3.6.3
 Markdown==2.6.6
 pelican-advthumbnailer==0.5.0
+piexif==1.1.3
+Pillow==5.0.0
-- 
GitLab