Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement use of make #22

Merged
merged 11 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 37 additions & 50 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions .docker/blog.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
71 changes: 71 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
hugo --gc --minify
2 changes: 2 additions & 0 deletions scripts/ci/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
netlify deploy --site $1 --auth $2 --prod --dir=public
16 changes: 16 additions & 0 deletions scripts/ci/verify.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions scripts/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Building Docker image..."
docker build -f .docker/blog.Dockerfile -t airscript/blog:$1 .
3 changes: 3 additions & 0 deletions scripts/docker/login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Logging into Docker Hub..."
docker login --username $1 --password $2
3 changes: 3 additions & 0 deletions scripts/docker/push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Pushing image to Docker Hub..."
docker push airscript/blog:$1
2 changes: 2 additions & 0 deletions scripts/install/docker-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
apk add docker-cli
2 changes: 1 addition & 1 deletion scripts/git.sh → scripts/install/git.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
if [ ! "$1" = "compose" ]; then
apk add git
fi
fi
2 changes: 2 additions & 0 deletions scripts/install/hugo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
apk add hugo
2 changes: 2 additions & 0 deletions scripts/install/make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
apk add make
2 changes: 2 additions & 0 deletions scripts/install/netlify-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
npm install -g netlify-cli
2 changes: 2 additions & 0 deletions scripts/install/npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
npm install -g npm
File renamed without changes.