From 65d35cd28bfb940fab95e5e012f2079eeac62037 Mon Sep 17 00:00:00 2001 From: Airscript Date: Wed, 10 Aug 2022 11:52:31 +0000 Subject: [PATCH 1/3] feat(docker): add docker support and publish workflow --- .circleci/config.yml | 85 ++++++++++++++++++++++++++++++++++------- .docker/blog.Dockerfile | 23 +++++++++++ README.md | 26 ++++++++++++- VERSION | 2 +- config.toml | 2 +- docker-compose.yml | 24 ++++++++++++ docker-entrypoint.sh | 8 ++++ 7 files changed, 152 insertions(+), 18 deletions(-) create mode 100644 .docker/blog.Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker-entrypoint.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index fa3c35e..00c62db 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,23 +1,53 @@ version: 2.1 executors: - alpine-environment: + build-environment: + docker: + - image: alpine:3.16 + + deploy-environment: docker: - image: node:18.7.0-alpine3.16 + + publish-environment: + docker: + - image: docker:20.10.17-cli-alpine3.16 jobs: - verify: - executor: alpine-environment + verify-build-environment: + executor: build-environment steps: - - checkout + - run: + name: "Verify apk" + command: "apk" + + verify-deploy-environment: + executor: deploy-environment + + steps: + - run: + name: "Verify apk" + command: "apk" + + - run: + name: "Verify Node.js" + command: "node -v" + + - run: + name: "Verify npm" + command: "npm -v" + + verify-publish-environment: + executor: publish-environment + steps: - run: - name: "Verify Job" - command: "echo Verify job is working!" + name: "Verify Docker" + command: "docker -v" build: - executor: alpine-environment + executor: build-environment steps: - checkout @@ -49,7 +79,7 @@ jobs: - ./public deploy: - executor: alpine-environment + executor: deploy-environment steps: - checkout @@ -61,10 +91,6 @@ jobs: name: "Update Alpine Repositories" command: "apk update" - - run: - name: "Install Git" - command: "apk add git" - - run: name: "Update npm" command: "npm install -g npm" @@ -76,11 +102,31 @@ jobs: - run: name: "Deploy To Netlify" command: "netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_ACCESS_TOKEN --prod --dir=public" - + + publish: + executor: publish-environment + + steps: + - checkout + + - run: + name: "Login Into Docker Hub" + command: "docker login --username $DOCKER_USERNAME --password $DOCKER_ACCESS_TOKEN" + + - run: + name: "Build Docker Image" + command: "docker build -f .docker/blog.Dockerfile -t airscript/blog:$CIRCLE_TAG ." + + - run: + name: "Publish To Docker Hub" + command: "docker push airscript/blog:$CIRCLE_TAG" + workflows: verify: jobs: - - verify + - verify-build-environment + - verify-deploy-environment + - verify-publish-environment build: jobs: @@ -89,6 +135,7 @@ workflows: deploy: jobs: - build + - deploy: requires: - build @@ -97,3 +144,13 @@ workflows: branches: only: - main + publish: + jobs: + - publish: + filters: + tags: + only: + - /.*/ + + branches: + ignore: /.*/ \ No newline at end of file diff --git a/.docker/blog.Dockerfile b/.docker/blog.Dockerfile new file mode 100644 index 0000000..7c3b960 --- /dev/null +++ b/.docker/blog.Dockerfile @@ -0,0 +1,23 @@ +FROM node:18.7.0-alpine3.16 + +LABEL maintainer="Airscript " + +ENV BLOG_PORT=25001 +ENV BLOG_INTERFACE=0.0.0.0 + +ARG BLOG_DIR=app + +RUN apk update +RUN apk add git +RUN apk add hugo + +RUN mkdir ${BLOG_DIR} +WORKDIR /${BLOG_DIR} + +COPY . . +RUN git submodule update --init --recursive + +ENTRYPOINT ["./docker-entrypoint.sh"] +CMD ["hugo"] + +EXPOSE ${BLOG_PORT} diff --git a/README.md b/README.md index cdd90ee..9d582fe 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,27 @@ [![CircleCI](https://dl.circleci.com/status-badge/img/gh/Airscripts/blog.airscript.it/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/Airscripts/blog.airscript.it/tree/main) [![Netlify Status](https://api.netlify.com/api/v1/badges/59826574-7ccb-4c30-a776-942044cf9520/deploy-status?branch=main)](https://app.netlify.com/sites/regal-sunshine-3cc2d8/deploys) This repository contains source code and content of my blog hosted on [blog.airscript.it](https://blog.airscript.it). +  ## 📦 Installation +In order to the use correct version of Hugo it is **recommended** to use Docker. +  + +### 🐳 Containerized Environment +1. Install Docker and Docker Compose on your machine following these links: +- [Docker](https://docs.docker.com/get-docker/) +- [Docker Compose](https://docs.docker.com/compose/install/) + +2. Run the following commands in the repository's root folder: + ```bash + docker compose build + docker compose up + ``` + +3. Everything should be set up and running on port 25001. +  + +### 💻 Local Environment 1. Clone this repository: ```bash git clone https://github.com/Airscripts/blog.airscript.it.git @@ -19,10 +38,12 @@ This repository contains source code and content of my blog hosted on [blog.airs 4. Run the following command: ```bash hugo server - ``` + ``` +  ## 🤝 Contributing Contributions and suggestions about how to improve the blog are welcome! +  ## 💚 Support If you want to support my work you can do it with the links below. @@ -31,7 +52,8 @@ Choose what you find more suitable for you: - [Support me on GitHub](https://github.com/sponsors/Airscripts) - [Support me via linktr.ee](https://linktr.ee/airscript) -Thank you so much, it means a lot for me! +Thank you so much, it means a lot for me! +  ## 💳 License This repository has dual-licensing. diff --git a/VERSION b/VERSION index afaf360..1cc5f65 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.1.0 \ No newline at end of file diff --git a/config.toml b/config.toml index d5653c8..5a13b69 100644 --- a/config.toml +++ b/config.toml @@ -7,7 +7,7 @@ pygmentsUseClasses = true enableInlineShortcodes = true defaultContentLanguage = "it" baseURL = "https://blog.airscript.it" -copyright = "airscript.it (1.0.0) | Sharing happiness with code." +copyright = "airscript.it (1.1.0) | Sharing happiness with code." [languages.it] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b21ec77 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3.9" + +services: + blog: + tty: true + restart: always + image: airscript/blog:1.1.0 + container_name: airscript-blog + + ports: + - "25001:25001/udp" + - "25001:25001/tcp" + + volumes: + - .:/app + + networks: + default: + aliases: + - blognet + + build: + context: . + dockerfile: ".docker/blog.Dockerfile" \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..32c73f6 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +if [ "$1" = 'hugo' ]; then + hugo server --bind $BLOG_INTERFACE --port $BLOG_PORT +fi + +exec "$@" \ No newline at end of file From 452765305c4da12008c3c2a118dc19785b2b3246 Mon Sep 17 00:00:00 2001 From: Airscript Date: Wed, 10 Aug 2022 11:56:55 +0000 Subject: [PATCH 2/3] fix(ci): add missin --version flag to apk command --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 00c62db..e6b6031 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ jobs: steps: - run: name: "Verify apk" - command: "apk" + command: "apk --version" verify-deploy-environment: executor: deploy-environment @@ -28,7 +28,7 @@ jobs: steps: - run: name: "Verify apk" - command: "apk" + command: "apk --version" - run: name: "Verify Node.js" From f007491872b060068c08a7e6a5623d4534de0dff Mon Sep 17 00:00:00 2001 From: Airscript Date: Wed, 10 Aug 2022 13:12:13 +0000 Subject: [PATCH 3/3] feat(ci): add conditional persistence to workspace --- .circleci/config.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e6b6031..f92018e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -71,13 +71,18 @@ jobs: - run: name: "Building Site" command: "hugo --gc --minify" - - - persist_to_workspace: - root: . - paths: - - ./public - + - when: + condition: + equal: [ main, << pipeline.git.branch >>] + + steps: + - persist_to_workspace: + root: . + + paths: + - ./public + deploy: executor: deploy-environment