diff --git a/.circleci/config.yml b/.circleci/config.yml index b812c35..6587204 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,181 +5,21 @@ setup: true orbs: path-filtering: circleci/path-filtering@0.1.3 -executors: - build-environment: - docker: - - image: alpine:3.16 - - deploy-environment: - docker: - - image: node:18.7.0-alpine3.16 - - publish-environment: - docker: - - image: alpine:3.16 - -jobs: - verify-build-environment: - executor: build-environment - - steps: - - checkout - - - run: - name: Verify Environment - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/ci/verify.sh build - - verify-deploy-environment: - executor: deploy-environment - - steps: - - checkout - - - run: - name: Verify Environment - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/ci/verify.sh deploy - - verify-publish-environment: - executor: publish-environment - - steps: - - checkout - - - run: - name: Verify Environment - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/ci/verify.sh publish - - build: - executor: build-environment - - steps: - - checkout - - - run: - name: Install Packages - - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/install/make.sh - make install-git env=$BLOG_BUILD_ENV - make install-hugo - - - run: - name: Add Git Submodules - command: make git-submodules env=$BLOG_BUILD_ENV - - - run: - name: Building Site - command: make build-ci - - - when: - condition: - equal: [ main, << pipeline.git.branch >>] - - steps: - - persist_to_workspace: - root: . - - paths: - - ./public - - deploy: - executor: deploy-environment - - steps: - - checkout - - - attach_workspace: - at: . - - - run: - name: Install Packages - - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/install/make.sh - make install-npm - make install-netlify-cli - - - run: - name: Deploy To Netlify - command: make deploy-ci id=$NETLIFY_SITE_ID token=$NETLIFY_ACCESS_TOKEN - - publish: - executor: publish-environment - - steps: - - checkout - - - setup_remote_docker: - docker_layer_caching: true - version: 20.10.14 - - - run: - name: Install Packages - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/install/make.sh - make install-docker-cli - - - run: - name: Publish To Docker Hub - command: make publish-ci tag=$CIRCLE_TAG username=$DOCKER_USERNAME token=$DOCKER_ACCESS_TOKEN - workflows: - main: + setup: jobs: - - verify-build-environment - - - verify-deploy-environment: - filters: - branches: - only: - - main - - - verify-publish-environment: - filters: - branches: - only: - - main - - - build - - path-filtering/filter: - name: watchtower - - mapping: | - tests/.* run-tests-jobs true - + name: workflows base-revision: main - config-path: .circleci/watchtower.yml - - - deploy: - requires: - - build - - filters: - branches: - only: - - main + config-path: .circleci/workflows.yml - - publish: - filters: - tags: - only: - - /.*/ - - branches: - ignore: /.*/ + mapping: | + tests/.* test true + data/.* build true + i18n/.* build true + static/.* build true + content/.* build true + layouts/.* build true + resources/.* build true + archetypes/.* build true + config.toml/.* build true diff --git a/.circleci/watchtower.yml b/.circleci/watchtower.yml deleted file mode 100644 index 38e5bab..0000000 --- a/.circleci/watchtower.yml +++ /dev/null @@ -1,72 +0,0 @@ -version: 2.1 - -parameters: - run-tests-jobs: - type: boolean - default: false - -executors: - tests-node-environment: - docker: - - image: node:18.7.0-alpine3.16 - - tests-bats-environment: - docker: - - image: bats/bats:1.7.0 - -jobs: - tests-bats: - executor: tests-bats-environment - - steps: - - checkout - - - run: - name: Install Packages - - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/install/make.sh - make install-git env=$BLOG_BUILD_ENV - - - run: - name: Add Git Submodules - command: make git-submodules env=$BLOG_BUILD_ENV - - - run: - name: Run Tests - command: bats ./tests/_.bats ./tests/install.bats ./tests/shared.bats - - tests-node: - executor: tests-node-environment - - steps: - - checkout - - - run: - name: Install Packages - - command: | - apk update - sh scripts/install/bash.sh $BLOG_BUILD_ENV - bash scripts/install/make.sh - make install-git env=$BLOG_BUILD_ENV - npm install -g bats - - - run: - name: Add Git Submodules - command: make git-submodules env=$BLOG_BUILD_ENV - - - run: - name: Run Node Tests - command: bats tests/_.bats tests/install-node.bats - - -workflows: - test: - when: << pipeline.parameters.run-tests-jobs >> - - jobs: - - tests-bats - - tests-node diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml new file mode 100644 index 0000000..20f9518 --- /dev/null +++ b/.circleci/workflows.yml @@ -0,0 +1,291 @@ +version: 2.1 + +parameters: + verify: + type: boolean + default: true + + test: + type: boolean + default: false + + build: + type: boolean + default: false + + deploy: + type: boolean + default: true + + publish: + type: boolean + default: true + +executors: + base: + docker: + - image: alpine:3.16 + +commands: + setup: + steps: + - run: + name: Setup + + command: | + sh scripts/update.sh + sh scripts/install/bash.sh + bash scripts/install/make.sh + + setup-git: + steps: + - install-git + + - run: + name: Setup Git + command: make git-submodules environment=$CI_ENVIRONMENT + + setup-netlify: + steps: + - install-npm + - install-netlify-cli + + install-git: + steps: + - run: + name: "Install Git" + command: make install-git environment=$CI_ENVIRONMENT + + install-npm: + steps: + - run: + name: Install npm + command: make install-npm + + install-hugo: + steps: + - run: + name: Install Hugo + command: make install-hugo + + install-bats: + steps: + - run: + name: Install Bats + command: make install-bats + + install-docker-cli: + steps: + - run: + name: Install Docker CLI + command: make install-docker-cli + + install-netlify-cli: + steps: + - run: + name: Install Netlify CLI + command: make install-netlify-cli + +jobs: + verify: + executor: base + + steps: + - checkout + - setup + + - run: + name: Verify Base + command: make verify-ci environment=base + + verify-build: + executor: base + + steps: + - checkout + - setup + - setup-git + - install-hugo + + - run: + name: Verify Build + command: make verify-ci environment=build + + verify-deploy: + executor: base + + steps: + - checkout + - setup + - setup-netlify + + - run: + name: Verify Deploy + command: make verify-ci environment=deploy + + verify-publish: + executor: base + + steps: + - checkout + - setup + - install-docker-cli + + - run: + name: Verify Publish + command: make verify-ci environment=publish + + tests: + executor: base + + steps: + - checkout + - setup + - setup-git + - install-npm + - install-bats + + - run: + name: Run Tests + command: > + bats + tests/* + + build: + executor: base + + steps: + - checkout + - setup + - setup-git + - install-hugo + + - run: + name: Build Site + command: make build-ci + + - when: + condition: + equal: [ main, << pipeline.git.branch >>] + + steps: + - persist_to_workspace: + root: . + + paths: + - ./public + + deploy: + executor: base + + steps: + - checkout + - setup + - setup-netlify + + - attach_workspace: + at: . + + - run: + name: Deploy To Netlify + command: > + make deploy-ci + id=$NETLIFY_SITE_ID + token=$NETLIFY_ACCESS_TOKEN + + publish: + executor: base + + steps: + - checkout + - setup + - install-docker-cli + + - setup_remote_docker: + docker_layer_caching: true + version: 20.10.14 + + - run: + name: Publish To Docker Hub + command: > + make publish-ci + tag=$CIRCLE_TAG + username=$DOCKER_USERNAME + token=$DOCKER_ACCESS_TOKEN + +workflows: + verify: + when: << pipeline.parameters.verify >> + + jobs: + - verify + + test: + when: << pipeline.parameters.test >> + + jobs: + - tests + + build: + when: << pipeline.parameters.build >> + + jobs: + - verify-build + + - build: + requires: + - verify-build + + deploy: + when: << pipeline.parameters.deploy >> + + jobs: + - verify-build: + filters: + branches: + only: + - main + + - build: + requires: + - verify-build + + filters: + branches: + only: + - main + + - deploy: + requires: + - build + + filters: + branches: + only: + - main + + publish: + when: << pipeline.parameters.publish >> + + jobs: + - verify-publish: + filters: + tags: + only: + - /.*/ + + branches: + ignore: /.*/ + + + - publish: + requires: + - verify-publish + + filters: + tags: + only: + - /.*/ + + branches: + ignore: /.*/ diff --git a/.docker/blog.Dockerfile b/.docker/blog.Dockerfile index eba5d47..0c3a0f3 100644 --- a/.docker/blog.Dockerfile +++ b/.docker/blog.Dockerfile @@ -6,21 +6,21 @@ ENV BLOG_PORT=25001 ENV BLOG_INTERFACE=0.0.0.0 ARG BLOG_DIR=app -ARG BLOG_BUILD_ENV=docker +ARG BLOG_BUILD_ENVIRONMENT=docker RUN \ -apk update && \ -apk add hugo && \ -apk add bash && \ -mkdir ${BLOG_DIR} + apk update && \ + apk add hugo && \ + apk add bash && \ + mkdir ${BLOG_DIR} WORKDIR /${BLOG_DIR} COPY . . RUN \ -sh ./scripts/install/git.sh ${BLOG_BUILD_ENV} && \ -sh ./scripts/shared/git-submodules.sh ${BLOG_BUILD_ENV} + sh ./scripts/install/git.sh ${BLOG_BUILD_ENVIRONMENT} && \ + sh ./scripts/shared/git-submodules.sh ${BLOG_BUILD_ENVIRONMENT} ENTRYPOINT ["./scripts/docker-entrypoint.sh"] diff --git a/Makefile b/Makefile index 68cbd7a..d807802 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ install-hugo: .PHONY: install-cli install-git: - sh ./scripts/install/git.sh $(env) + sh ./scripts/install/git.sh $(environment) .PHONY: install-docker-cli install-docker-cli: @@ -76,7 +76,7 @@ install-docker-cli: .PHONY: verify-ci verify-ci: - sh ./scripts/ci/verify.sh $(env) + sh ./scripts/ci/verify.sh $(environment) .PHONY: build-ci build-ci: @@ -91,7 +91,7 @@ publish-ci: docker-login docker-build docker-push .PHONY: git-submodules git-submodules: - sh ./scripts/shared/git-submodules.sh $(env) + sh ./scripts/shared/git-submodules.sh $(environment) .PHONY: docker-login docker-login: diff --git a/docker-compose.yml b/docker-compose.yml index e866796..234dd28 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,4 +23,4 @@ services: dockerfile: ".docker/blog.Dockerfile" args: - BLOG_BUILD_ENV: compose \ No newline at end of file + BLOG_BUILD_ENVIRONMENT: compose \ No newline at end of file diff --git a/scripts/ci/verify.sh b/scripts/ci/verify.sh index 47d2a79..792b095 100755 --- a/scripts/ci/verify.sh +++ b/scripts/ci/verify.sh @@ -1,14 +1,21 @@ #!/bin/bash -if [ "$1" = "build" ]; then +if [ "$1" = "base" ]; then apk --version + +elif [ "$1" = "build" ]; then + apk --version + git --version + hugo version elif [ "$1" = "deploy" ]; then apk --version node -v npm -v + netlify -v elif [ "$1" = "publish" ]; then apk --version + docker -v else echo ERROR: Environment not found. diff --git a/scripts/install/bats.sh b/scripts/install/bats.sh new file mode 100644 index 0000000..feb0126 --- /dev/null +++ b/scripts/install/bats.sh @@ -0,0 +1,2 @@ +#!/bin/bash +npm install -g bats diff --git a/scripts/install/npm.sh b/scripts/install/npm.sh index a3a5faa..e920f2f 100755 --- a/scripts/install/npm.sh +++ b/scripts/install/npm.sh @@ -1,3 +1,3 @@ #!/bin/bash -npm install -g npm +apk add npm echo "npm installed successfully." diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100644 index 0000000..b574be2 --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,2 @@ +#!/bin/sh +apk update