diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c8a6205f..69d826a0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -56,7 +56,7 @@ } }, "forwardPorts": [4000], - "image": "ghcr.io/nhsdigital/nhs-notify-template-repository:latest", + "image": "ghcr.io/nhsdigital/nhs-notify-web-cms:latest", "name": "Jekyll", "runArgs": ["--platform=linux/amd64"] } diff --git a/.github/workflows/devcontainer-build-publish.yaml b/.github/workflows/devcontainer-build-publish.yaml new file mode 100644 index 00000000..a48574db --- /dev/null +++ b/.github/workflows/devcontainer-build-publish.yaml @@ -0,0 +1,44 @@ +name: "Build and publish devcontainer" + +on: + push: + branches: + - main + paths: + - gem.lock + - docs/Gemfile.lock + - src/jekyll-devcontainer/** + workflow_dispatch: + +permissions: + contents: read + packages: write + +jobs: + build-and-publish: + name: "Build and publish Jekyll devcontainer" + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + BUILD_TARGET: devcontainer + DEVCONTAINER_IMAGE: ghcr.io/nhsdigital/nhs-notify-web-cms + steps: + - name: "Checkout code" + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + + - name: "Set up Node.js" + uses: actions/setup-node@v4 + with: + node-version: "22" + + - name: "Log in to GitHub Container Registry" + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + + - name: "Build devcontainer image" + run: | + make build + + - name: "Publish devcontainer image" + run: | + make publish diff --git a/Makefile b/Makefile index ea70e95e..cd74e41f 100644 --- a/Makefile +++ b/Makefile @@ -7,14 +7,32 @@ include scripts/init.mk # Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc. +DEVCONTAINER_DIR ?= src/jekyll-devcontainer +DEVCONTAINER_IMAGE ?= ghcr.io/nhsdigital/nhs-notify-web-cms + dependencies: # Install dependencies needed to build and test the project @Pipeline # TODO: Implement installation of your project dependencies build: # Build the project artefact @Pipeline - (cd docs && make build) + if [[ "$${BUILD_TARGET:-all}" == "devcontainer" ]]; then + make build-devcontainer + else + (cd docs && make build) + make build-devcontainer + fi publish: # Publish the project artefact @Pipeline - # TODO: Implement the artefact publishing step + if [[ "$${BUILD_TARGET:-all}" == "devcontainer" ]]; then + make publish-devcontainer + else + make publish-devcontainer + fi + +build-devcontainer: # Build the devcontainer image @Pipeline + make -C ${DEVCONTAINER_DIR} build IMAGE=${DEVCONTAINER_IMAGE} + +publish-devcontainer: # Publish the devcontainer image @Pipeline + make -C ${DEVCONTAINER_DIR} publish IMAGE=${DEVCONTAINER_IMAGE} deploy: # Deploy the project artefact to the target environment @Pipeline # TODO: Implement the artefact deployment step @@ -34,7 +52,10 @@ version: ${VERBOSE}.SILENT: \ build \ + build-devcontainer \ clean \ config \ dependencies \ deploy \ + publish \ + publish-devcontainer \ diff --git a/src/jekyll-devcontainer/Makefile b/src/jekyll-devcontainer/Makefile new file mode 100644 index 00000000..0174644a --- /dev/null +++ b/src/jekyll-devcontainer/Makefile @@ -0,0 +1,22 @@ +IMAGE ?= ghcr.io/nhsdigital/nhs-notify-web-cms + +build: + $(MAKE) -C ../../ version + ver=$$(head -n 1 ../../.version 2> /dev/null || echo unknown); \ + verb=$$(echo $$ver | sed 's/+.*//'); \ + echo "version: $$verb"; \ + BUILDKIT_PROGRESS=plain npx --yes @devcontainers/cli build --workspace-folder ./src --image-name "${IMAGE}:$$verb" + +publish: + ver=$$(head -n 1 ../../.version 2> /dev/null || echo unknown); \ + verb=$$(echo $$ver | sed 's/+.*//'); \ + echo "version: $$verb"; \ + docker image tag ${IMAGE}:$$verb ${IMAGE}:latest; \ + docker push "${IMAGE}:$$verb"; \ + docker push "${IMAGE}:latest" + +debug: + npx --yes @devcontainers/cli up --workspace-folder ./src + npx --yes @devcontainers/cli exec --workspace-folder ./src ls -la ./.devcontainer + npx --yes @devcontainers/cli exec --workspace-folder ./src cat ./.devcontainer/packages.txt + npx --yes @devcontainers/cli exec --workspace-folder ./src ./.devcontainer/check.sh \ No newline at end of file diff --git a/src/jekyll-devcontainer/README.md b/src/jekyll-devcontainer/README.md new file mode 100644 index 00000000..33c52bb6 --- /dev/null +++ b/src/jekyll-devcontainer/README.md @@ -0,0 +1,10 @@ +# Publishing + +To publish, create a classic token and run `docker login` before `make publish`. + +Docker login: + +```bash +export CR_PAT=YOUR_TOKEN +echo "$CR_PAT" | docker login ghcr.io -u USERNAME --password-stdin +``` \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/Dockerfile b/src/jekyll-devcontainer/src/.devcontainer/Dockerfile new file mode 100644 index 00000000..eb53bbec --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM --platform=linux/amd64 mcr.microsoft.com/devcontainers/jekyll:3.4-bookworm +LABEL org.opencontainers.image.source=https://github.com/NHSDigital/nhs-notify-web-cms + +COPY packages.txt packages.txt + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive xargs apt-get -yq install < packages.txt \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/check.sh b/src/jekyll-devcontainer/src/.devcontainer/check.sh new file mode 100755 index 00000000..f127ffd0 --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/check.sh @@ -0,0 +1,5 @@ +#! /bin/zsh + +cd ./.devcontainer +cat packages.txt +apt-get -s install < packages.txt \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/devcontainer-lock.json b/src/jekyll-devcontainer/src/.devcontainer/devcontainer-lock.json new file mode 100644 index 00000000..2ad7c887 --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/devcontainer-lock.json @@ -0,0 +1,29 @@ +{ + "features": { + "ghcr.io/devcontainers/features/aws-cli:1": { + "version": "1.1.4", + "resolved": "ghcr.io/devcontainers/features/aws-cli@sha256:1f93c8315b7a6d76982ebb2269f8b0d50413fc0f965c032edf4aee0caceb73ef", + "integrity": "sha256:1f93c8315b7a6d76982ebb2269f8b0d50413fc0f965c032edf4aee0caceb73ef" + }, + "ghcr.io/devcontainers/features/common-utils:2": { + "version": "2.5.9", + "resolved": "ghcr.io/devcontainers/features/common-utils@sha256:cb0c4d3c276f157eed17935747e364178d75fee17f55c4e129966f64633deb3a", + "integrity": "sha256:cb0c4d3c276f157eed17935747e364178d75fee17f55c4e129966f64633deb3a" + }, + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "version": "2.17.0", + "resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:25b9f05705ffba7dbe503230ac76081419306f8c8bc88e0ce78c4ecd99a0c78c", + "integrity": "sha256:25b9f05705ffba7dbe503230ac76081419306f8c8bc88e0ce78c4ecd99a0c78c" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "version": "1.1.0", + "resolved": "ghcr.io/devcontainers/features/github-cli@sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671", + "integrity": "sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671" + }, + "ghcr.io/devcontainers/features/node:1": { + "version": "1.7.1", + "resolved": "ghcr.io/devcontainers/features/node@sha256:8c0de46939b61958041700ee89e3493f3b2e4131a06dc46b4d9423427d06e5f6", + "integrity": "sha256:8c0de46939b61958041700ee89e3493f3b2e4131a06dc46b4d9423427d06e5f6" + } + } +} \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/devcontainer.json b/src/jekyll-devcontainer/src/.devcontainer/devcontainer.json new file mode 100644 index 00000000..b6cf9c2c --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/devcontainer.json @@ -0,0 +1,107 @@ +{ + "build": { + "dockerfile": "Dockerfile" + }, + "customizations": { + "codespaces": { + "openFiles": [ + "README.md", + ".github/SECURITY.md", + "docs/pages/index.md" + ] + }, + "vscode": { + "extensions": [ + "alefragnani.bookmarks", + "AmazonWebServices.aws-toolkit-vscode", + "chdsbd.github-code-owners", + "davidanson.vscode-markdownlint", + "dbaeumer.vscode-eslint", + "donjayamanne.githistory", + "editorconfig.editorconfig", + "esbenp.prettier-vscode", + "fvclaus.sort-json-array", + "github.codespaces", + "github.github-vscode-theme", + "github.remotehub", + "github.vscode-github-actions", + "github.vscode-pull-request-github", + "hediet.vscode-drawio", + "johnpapa.vscode-peacock", + "joshx.workspace-terminals", + "maattdd.gitless", + "mhutchie.git-graph", + "ms-azuretools.vscode-docker", + "ms-vscode-remote.remote-containers", + "ms-vscode-remote.remote-wsl", + "ms-vscode.hexeditor", + "ms-vscode.live-server", + "ms-vsliveshare.vsliveshare", + "redhat.vscode-xml", + "streetsidesoftware.code-spell-checker-british-english", + "takumii.markdowntable", + "tamasfe.even-better-toml", + "tomoki1207.pdf", + "vscode-icons-team.vscode-icons", + "vstirbu.vscode-mermaid-preview", + "wayou.vscode-todo-highlight", + "yzane.markdown-pdf", + "yzhang.dictionary-completion", + "yzhang.markdown-all-in-one", + "zoma.vscode-auto-open-workspace" + ], + "settings": { + "[makefile]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false + }, + "autoOpenWorkspace.enableAutoOpenIfSingleWorkspace": true, + "editor.formatOnSave": true, + "extensions.ignoreRecommendations": true, + "files.insertFinalNewline": true + } + } + }, + "features": { + "./nhsnotify": { + "version": "1.0.1" + }, + "ghcr.io/devcontainers/features/aws-cli:1": { + "version": "latest" + }, + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true, + "installOhMyZsh": true, + "installOhMyZshConfig": true, + "installZsh": true, + "upgradePackages": true, + "userGid": "automatic", + "userUid": "automatic", + "username": "automatic" + }, + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "azureDnsAutoDetection": true, + "dockerDashComposeVersion": "latest", + "installDockerBuildx": true, + "installDockerComposeSwitch": true, + "moby": true, + "version": "latest" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "installDirectlyFromGitHubRelease": true, + "version": "latest" + }, + "ghcr.io/devcontainers/features/node:1": { + "nodeGypDependencies": true, + "nvmVersion": "latest", + "version": "lts" + } + }, + "forwardPorts": [ + 4000 + ], + "name": "NHS Notify Web CMS Dev Container", + "runArgs": [ + "--platform=linux/amd64" + ] +} \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/devcontainer-feature.json b/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/devcontainer-feature.json new file mode 100644 index 00000000..b970fe89 --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/devcontainer-feature.json @@ -0,0 +1,11 @@ +{ + "dependsOn": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installOhMyZsh": true + } + }, + "id": "nhsnotify", + "name": "Notify Custom", + "postCreateCommand": "zsh /postcreatecommand.sh", + "version": "1.0.1" +} \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/install.sh b/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/install.sh new file mode 100755 index 00000000..b4d20689 --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/install.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +cp ./postcreatecommand.sh /postcreatecommand.sh + +cp ~/.zshrc /.zshrc +rm -Rf /.asdf +git clone https://github.com/asdf-vm/asdf.git /.asdf +chmod +x /.asdf/asdf.sh +echo '. /.asdf/asdf.sh' >> /.zshrc +echo '. /.asdf/completions/asdf.bash' >> /.zshrc +sed -i "/plugins=/c\plugins=(git ssh-agent sudo terraform dirhistory zsh-autosuggestions)" /.zshrc + +cat /.zshrc + +cp /.zshrc ~/.zshrc +source ~/.zshrc +mkdir -p /zsh/plugins/zsh-autosuggestions +git clone https://github.com/zsh-users/zsh-autosuggestions /zsh/plugins/zsh-autosuggestions \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/postcreatecommand.sh b/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/postcreatecommand.sh new file mode 100755 index 00000000..a5796a6c --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/nhsnotify/postcreatecommand.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +cp /.zshrc ~/.zshrc +cp -r /zsh/* ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} +ls -la ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} + +cat ~/.zshrc +source ~/.zshrc +echo 'asdf setup complete' + +make config +echo 'make config complete' + +jekyll --version && cd docs && bundle install +echo 'jekyll setup complete' \ No newline at end of file diff --git a/src/jekyll-devcontainer/src/.devcontainer/packages.txt b/src/jekyll-devcontainer/src/.devcontainer/packages.txt new file mode 100644 index 00000000..44f14cc0 --- /dev/null +++ b/src/jekyll-devcontainer/src/.devcontainer/packages.txt @@ -0,0 +1,39 @@ +ca-certificates +fonts-liberation +libasound2 +libatk-adaptor +libatk-bridge2.0-0 +libatk1.0-0 +libc6 +libcairo2 +libcups2 +libdbus-1-3 +libexpat1 +libfontconfig1 +libgbm1 +libgcc1 +libglib2.0-0 +libgtk-3-0 +libnspr4 +libnss3 +libpango-1.0-0 +libpangocairo-1.0-0 +libstdc++6 +libx11-6 +libx11-xcb1 +libxcb1 +libxcomposite1 +libxcursor1 +libxdamage1 +libxext6 +libxfixes3 +libxi6 +libxrandr2 +libxrender1 +libxss1 +libxtst6 +lsb-release +openbox +wget +xdg-utils +xorg \ No newline at end of file