diff --git a/.circleci/config.yml b/.circleci/config.yml index d77109b..12c647e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,33 +18,31 @@ jobs: executor: build-environment steps: + - checkout + - run: - name: "Verify apk" - command: "apk --version" + name: Verify Environment + command: sh ./scripts/ci/verify.sh build verify-deploy-environment: executor: deploy-environment steps: + - checkout + - run: - name: "Verify apk" - command: "apk --version" - - - run: - name: "Verify Node.js" - command: "node -v" + name: Verify Environment + command: sh ./scripts/ci/verify.sh deploy - - run: - name: "Verify npm" - command: "npm -v" - verify-publish-environment: executor: publish-environment steps: + - checkout + - run: - name: "Verify apk" - command: "apk --version" + name: Verify Environment + command: sh ./scripts/ci/verify.sh publish build: executor: build-environment @@ -53,24 +51,21 @@ jobs: - checkout - run: - name: "Update Alpine Repositories" - command: "apk update" + name: Install Packages - - run: - name: "Install Git" - command: "sh ./scripts/git.sh $BLOG_BUILD_ENV" + command: | + apk update + sh ./scripts/install/make.sh + make install-git env=$BLOG_BUILD_ENV + make install-hugo - run: - name: "Update Git Submodules" - command: "sh ./scripts/submodules.sh $BLOG_BUILD_ENV" - - - run: - name: "Install Hugo" - command: "apk add hugo" + name: Add Git Submodules + command: make git-submodules env=$BLOG_BUILD_ENV - run: - name: "Building Site" - command: "hugo --gc --minify" + name: Building Site + command: make build-ci - when: condition: @@ -93,20 +88,17 @@ jobs: at: . - run: - name: "Update Alpine Repositories" - command: "apk update" + name: Install Packages - - run: - name: "Update npm" - command: "npm install -g npm" - - - run: - name: "Install Netlify CLI" - command: "npm install -g netlify-cli" + command: | + apk update + sh ./scripts/install/make.sh + make install-npm + make install-netlify-cli - run: - name: "Deploy To Netlify" - command: "netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_ACCESS_TOKEN --prod --dir=public" + name: Deploy To Netlify + command: make deploy-ci id=$NETLIFY_SITE_ID token=$NETLIFY_ACCESS_TOKEN publish: executor: publish-environment @@ -119,20 +111,15 @@ jobs: version: 20.10.14 - run: - name: "Install Docker CLI" - command: apk add docker-cli - - - 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 ." + name: Install Packages + command: | + apk update + sh ./scripts/install/make.sh + make install-docker-cli - run: - name: "Publish To Docker Hub" - command: "docker push airscript/blog:$CIRCLE_TAG" + name: Publish To Docker Hub + command: make publish-ci tag=$CIRCLE_TAG username=$DOCKER_USERNAME token=$DOCKER_ACCESS_TOKEN workflows: verify: diff --git a/.docker/blog.Dockerfile b/.docker/blog.Dockerfile index 88f2551..6b5a1d5 100644 --- a/.docker/blog.Dockerfile +++ b/.docker/blog.Dockerfile @@ -8,13 +8,18 @@ ENV BLOG_INTERFACE=0.0.0.0 ARG BLOG_DIR=app ARG BLOG_BUILD_ENV=docker -RUN apk update && apk add hugo && mkdir ${BLOG_DIR} +RUN \ +apk update && \ +apk add hugo && \ +mkdir ${BLOG_DIR} WORKDIR /${BLOG_DIR} COPY . . -RUN sh ./scripts/git.sh ${BLOG_BUILD_ENV} && sh ./scripts/submodules.sh ${BLOG_BUILD_ENV} +RUN \ +sh ./scripts/install/git.sh ${BLOG_BUILD_ENV} && \ +sh ./scripts/shared/git-submodules.sh ${BLOG_BUILD_ENV} ENTRYPOINT ["./scripts/docker-entrypoint.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..756a4c2 --- /dev/null +++ b/Makefile @@ -0,0 +1,71 @@ +SHELL = /bin/sh + +.SUFFIXES: +.SUFFIXES: .sh + +.PHONY: all +all: build run + +.PHONY: clean +clean: + docker compose down + cd ./themes/PaperMod && find . -name "*" -delete + +.PHONY: build +build: git-submodules + docker compose build + +.PHONY: run +run: + docker compose up -d + +.PHONY: install-npm +install-npm: + sh ./scripts/install/npm.sh + +.PHONY: install-netlify-cli +install-netlify-cli: + sh ./scripts/install/netlify-cli.sh + +.PHONY: install-hugo +install-hugo: + sh ./scripts/install/hugo.sh + +.PHONY: install-cli +install-git: + sh ./scripts/install/git.sh $(env) + +.PHONY: install-docker-cli +install-docker-cli: + sh ./scripts/install/docker-cli.sh + +.PHONY: verify-ci +verify-ci: + sh ./scripts/ci/verify.sh $(env) + +.PHONY: build-ci +build-ci: + sh ./scripts/ci/build.sh + +.PHONY: deploy-ci +deploy-ci: + sh ./scripts/ci/deploy.sh $(id) $(token) + +.PHONY: publish-ci +publish-ci: docker-login docker-build docker-push + +.PHONY: git-submodules +git-submodules: + sh ./scripts/shared/git-submodules.sh $(env) + +.PHONY: docker-login +docker-login: + sh ./scripts/docker/login.sh $(username) $(token) + +.PHONY: docker-build +docker-build: + sh ./scripts/docker/build.sh $(tag) + +.PHONY: docker-push +docker-push: + sh ./scripts/docker/push.sh $(tag) diff --git a/README.md b/README.md index c245eb5..35975c7 100644 --- a/README.md +++ b/README.md @@ -5,41 +5,27 @@ This repository contains source code and content of my blog hosted on [blog.airs   ## 📦 Installation -In order to the use correct version of Hugo it is **recommended** to use Docker. +In order to contribute to this project, you need an up and running development environment. +Follow the steps below in order to have one fully functional.   -### ⚙️ Common Steps 1. Clone this repository: ```bash git clone https://github.com/Airscripts/blog.airscript.it.git ``` -2. Update git submodules: - ```bash - sh init.sh - ``` - -### 🐳 Containerized Environment -1. Install Docker and Docker Compose on your machine following these links: +2. Make sure to have these dependencies installed on your machine: +- [Make](https://www.gnu.org/software/make/) +- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) - [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: +3. Run the following command in the repository's root folder: ```bash - docker compose build - docker compose up + make all ``` -3. Everything should be set up and running on port 25001. -  - -### 💻 Local Environment -1. Install Hugo following this [guide](https://gohugo.io/getting-started/installing/). - -2. Run the following command: - ```bash - hugo server - ``` +4. Everything should be set up and running on port 25001.   ## 🤝 Contributing diff --git a/scripts/ci/build.sh b/scripts/ci/build.sh new file mode 100644 index 0000000..86dde72 --- /dev/null +++ b/scripts/ci/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +hugo --gc --minify diff --git a/scripts/ci/deploy.sh b/scripts/ci/deploy.sh new file mode 100644 index 0000000..9e5b17c --- /dev/null +++ b/scripts/ci/deploy.sh @@ -0,0 +1,2 @@ +#!/bin/sh +netlify deploy --site $1 --auth $2 --prod --dir=public diff --git a/scripts/ci/verify.sh b/scripts/ci/verify.sh new file mode 100644 index 0000000..ccdcad8 --- /dev/null +++ b/scripts/ci/verify.sh @@ -0,0 +1,16 @@ +#!/bin/sh +if [ "$1" = "build" ]; then + apk --version + +elif [ "$1" = "deploy" ]; then + apk --version + node -v + npm -v + +elif [ "$1" = "publish" ]; then + apk --version + +else + echo ERROR: Environment not found. + exit 1 +fi \ No newline at end of file diff --git a/scripts/docker/build.sh b/scripts/docker/build.sh new file mode 100644 index 0000000..0c122e6 --- /dev/null +++ b/scripts/docker/build.sh @@ -0,0 +1,3 @@ +#!/bin/sh +echo "Building Docker image..." +docker build -f .docker/blog.Dockerfile -t airscript/blog:$1 . \ No newline at end of file diff --git a/scripts/docker/login.sh b/scripts/docker/login.sh new file mode 100644 index 0000000..3b75764 --- /dev/null +++ b/scripts/docker/login.sh @@ -0,0 +1,3 @@ +#!/bin/sh +echo "Logging into Docker Hub..." +docker login --username $1 --password $2 diff --git a/scripts/docker/push.sh b/scripts/docker/push.sh new file mode 100644 index 0000000..1985431 --- /dev/null +++ b/scripts/docker/push.sh @@ -0,0 +1,3 @@ +#!/bin/sh +echo "Pushing image to Docker Hub..." +docker push airscript/blog:$1 \ No newline at end of file diff --git a/scripts/install/docker-cli.sh b/scripts/install/docker-cli.sh new file mode 100644 index 0000000..9ec1f86 --- /dev/null +++ b/scripts/install/docker-cli.sh @@ -0,0 +1,2 @@ +#!/bin/sh +apk add docker-cli diff --git a/scripts/git.sh b/scripts/install/git.sh similarity index 94% rename from scripts/git.sh rename to scripts/install/git.sh index 38ffc34..b18e5f6 100644 --- a/scripts/git.sh +++ b/scripts/install/git.sh @@ -1,4 +1,4 @@ #!/bin/sh if [ ! "$1" = "compose" ]; then apk add git -fi \ No newline at end of file +fi diff --git a/scripts/install/hugo.sh b/scripts/install/hugo.sh new file mode 100644 index 0000000..92ce713 --- /dev/null +++ b/scripts/install/hugo.sh @@ -0,0 +1,2 @@ +#!/bin/sh +apk add hugo diff --git a/scripts/install/make.sh b/scripts/install/make.sh new file mode 100644 index 0000000..bd3a72d --- /dev/null +++ b/scripts/install/make.sh @@ -0,0 +1,2 @@ +#!/bin/sh +apk add make diff --git a/scripts/install/netlify-cli.sh b/scripts/install/netlify-cli.sh new file mode 100644 index 0000000..1acd046 --- /dev/null +++ b/scripts/install/netlify-cli.sh @@ -0,0 +1,2 @@ +#!/bin/sh +npm install -g netlify-cli diff --git a/scripts/install/npm.sh b/scripts/install/npm.sh new file mode 100644 index 0000000..d0a1eee --- /dev/null +++ b/scripts/install/npm.sh @@ -0,0 +1,2 @@ +#!/bin/sh +npm install -g npm diff --git a/scripts/submodules.sh b/scripts/shared/git-submodules.sh similarity index 100% rename from scripts/submodules.sh rename to scripts/shared/git-submodules.sh