Skip to content

Commit

Permalink
update build infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Nov 28, 2024
1 parent b19bd44 commit ff5f5a9
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 104 deletions.
24 changes: 24 additions & 0 deletions .devcontainer/.git_branch_bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GIT_BRANCH_COLOR_CLEAN=$(tput setaf 2)
GIT_BRANCH_COLOR_DIRTY=$(tput setaf 1)
BOLD=$(tput bold)
NORM=$(tput sgr0)
NO_COLOR=$(tput sgr0)

parse_git_branch()
{
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/')

if [[ -n $branch ]]
then
if [ -n "$(git status --untracked-files=no --porcelain)" ]
then
# Uncommitted changes
branch+='*'
echo "${GIT_BRANCH_COLOR_DIRTY}${BOLD}${branch}${NORM}${NO_COLOR}"
else
echo "${GIT_BRANCH_COLOR_CLEAN}${branch}${NO_COLOR}"
fi
fi
}

export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]\[\033[01;34m\] \w\[\$(parse_git_branch)\]\[\e[00m\]\n> "
66 changes: 44 additions & 22 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,75 @@
FROM ubuntu:23.04
FROM ubuntu:24.04

ARG ENV_FILE=/home/ubuntu/.env_setup
ARG project_dir=/home/ubuntu/project
ARG ruby_version=3.1.4
ARG node_version=16.13.2

ENV RUBY_VERSION=${ruby_version}
ENV NODE_VERSION=${node_version}

RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
curl \
git \
ca-certificates \
ruby-full \
build-essential \
openssh-client \
sudo \
zlib1g-dev

# Disable password prompt for sudo commands
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER ubuntu
WORKDIR /home/ubuntu
WORKDIR ${project_dir}

RUN \
curl -sSL https://get.rvm.io | bash -s stable && \
/home/ubuntu/.rvm/bin/rvm install ${ruby_version} && \
/home/ubuntu/.rvm/bin/rvm use ${ruby_version}

RUN \
echo "#!/bin/bash" >> $ENV_FILE && \
echo "export GEM_HOME=/home/ubuntu/gems" >> $ENV_FILE && \
echo "export GEM_PATH=/home/ubuntu/gems" >> $ENV_FILE && \
echo "export NVM_DIR=/home/ubuntu/.nvm" >> $ENV_FILE && \
echo "export PATH=\"/home/ubuntu/gems/bin:$PATH\"" >> $ENV_FILE && \
echo '[ -s $NVM_DIR/nvm.sh ] && \. $NVM_DIR/nvm.sh || true' >> $ENV_FILE
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

COPY \
.devcontainer/.git_branch_bash \
/home/ubuntu

# Temporarily add Makefile, Gemfile and NPM package files so that installation is done during
# the container build phase.
ADD \

RUN mkdir ${project_dir}/scripts

COPY \
Makefile \
Gemfile \
Gemfile.lock \
package.json \
package-lock.json \
/home/ubuntu
${project_dir}

COPY \
scripts/env_setup.sh \
${project_dir}/scripts

RUN \
sudo chown ubuntu:ubuntu \
/home/ubuntu/package.json \
/home/ubuntu/package-lock.json \
&& \
sudo chmod 666 \
Gemfile.lock \
package-lock.json && \
make install && \
rm \
/home/ubuntu/Makefile \
/home/ubuntu/Gemfile \
/home/ubuntu/Gemfile.lock \
/home/ubuntu/package.json \
/home/ubuntu/package-lock.json
rm Makefile \
Gemfile \
Gemfile.lock \
package.json \
package-lock.json && \
rm -rf ${project_dir}/scripts

RUN \
tee -a /home/ubuntu/.bashrc <<EOF
alias mkc='make clean'
source /home/ubuntu/.git_branch_bash
source /usr/share/bash-completion/completions/git
EOF

EXPOSE 3000
52 changes: 35 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
{
"name": "Shantea Controls Website",
"dockerComposeFile": [
"../docker-compose-build.yml"
],
"service": "shanteacontrols-website",
"workspaceFolder": "/home/ubuntu/website",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"llvm-vs-code-extensions.vscode-clangd",
"eamodio.gitlens",
"xaver.clang-format",
"timonwong.shellcheck"
]
}
}
"name": "${localWorkspaceFolderBasename}",
"build": {
"dockerfile": "Dockerfile",
"context": "${localWorkspaceFolder}"
},
"workspaceMount": "src=${localWorkspaceFolder},dst=/home/ubuntu/project,type=bind",
"workspaceFolder": "/home/ubuntu/project",
"mounts": [
{
"source": "${localEnv:HOME}/.gitconfig",
"target": "/etc/gitconfig",
"type": "bind"
},
{
"source": "${localEnv:HOME}/.ssh",
"target": "/home/ubuntu/.ssh",
"type": "bind"
}
],
"runArgs": [
"--network=host",
"--hostname=${localWorkspaceFolderBasename}",
],
"containerUser": "ubuntu",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"llvm-vs-code-extensions.vscode-clangd",
"eamodio.gitlens",
"xaver.clang-format",
"timonwong.shellcheck"
]
}
}
}
50 changes: 33 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,40 @@ on:
jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04
container:
image: paradajz168/website-dev:latest
options: --user root
runs-on: ubuntu-latest
steps:
- name: Mark repository as safe
run: git config --global --add safe.directory /__w/website/website
- name: Checkout repository
uses: actions/checkout@v3
- name: Pull the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Deploy
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup missing directories and files on the runner
run: |
git config --global user.name "web_bot"
git config --global user.email "2544094+web_bot@users.noreply.github.com"
make prod
git checkout gh-pages
cp -R _site/deploy/* .
git add .
git commit --allow-empty -m "update"
git push https://github.com/shanteacontrols/website gh-pages
mkdir -p ~/.ssh
touch ~/.gitconfig
- name: Prepare container
uses: devcontainers/ci@v0.3
with:
imageName: website # Local name only
imageTag: latest # Local tag only
push: never
- name: Deploy
uses: devcontainers/ci@v0.3
with:
imageName: website
imageTag: latest
push: never
runCmd: |
git config --global user.name "web_bot"
git config --global user.email "2544094+web_bot@users.noreply.github.com"
make prod
git checkout gh-pages
cp -R _site/deploy/* .
git add .
git commit --allow-empty -m "update"
git push https://github.com/shanteacontrols/website gh-pages
76 changes: 65 additions & 11 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,74 @@ on:
- '.devcontainer/Dockerfile'

jobs:
update_docker:
runs-on: ubuntu-22.04
x86-64:
name: Build Docker Container / x86-64
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
- name: Pull the repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Push to docker hub
uses: docker/build-push-action@v2
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to registry
uses: docker/build-push-action@v5
with:
push: true
context: .
platforms: linux/amd64
file: .devcontainer/Dockerfile
tags: |
ghcr.io/shanteacontrols/website:${{ github.sha }}-x86-64
arm64:
name: Build Docker Container / arm64
runs-on: self-hosted
steps:
- name: Pull the repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to registry
uses: docker/build-push-action@v5
with:
push: true
tags: paradajz168/website-dev:latest
context: .
platforms: linux/arm64
file: .devcontainer/Dockerfile
tags: |
ghcr.io/shanteacontrols/website:${{ github.sha }}-arm64
create-manifests:
name: Create Docker manifests
runs-on: ubuntu-latest
needs: [x86-64, arm64]
steps:
- name: Pull the repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: SHA manifest
run: |
docker buildx imagetools create -t ghcr.io/shanteacontrols/website:${{ github.sha }} \
ghcr.io/shanteacontrols/website:${{ github.sha }}-x86-64 \
ghcr.io/shanteacontrols/website:${{ github.sha }}-arm64
- name: latest manifest
run: |
docker buildx imagetools create -t ghcr.io/shanteacontrols/website:latest \
ghcr.io/shanteacontrols/website:${{ github.sha }}-x86-64 \
ghcr.io/shanteacontrols/website:${{ github.sha }}-arm64
6 changes: 2 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GEM
eventmachine (1.2.7)
ffi (1.15.5)
forwardable-extended (2.6.0)
google-protobuf (3.21.12-x86_64-linux)
google-protobuf (3.25.5-x86_64-linux)
http_parser.rb (0.8.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -58,16 +58,14 @@ GEM
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (5.0.1)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.5)
rouge (4.0.1)
safe_yaml (1.0.5)
sass-embedded (1.57.1)
sass-embedded (1.57.1-x86_64-linux-gnu)
google-protobuf (~> 3.21)
rake (>= 10.0.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.4.1)
Expand Down
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SHELL := /bin/bash
ROOT_DIR := /home/ubuntu
ENV_FILE := $(ROOT_DIR)/.env_setup
NODE_VERSION := 16.13.2
SHELL := /bin/bash
ROOT_MAKEFILE_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
ENV_FILE := $(ROOT_MAKEFILE_DIR)/scripts/env_setup.sh

.DEFAULT_GOAL := dev

Expand All @@ -21,10 +20,6 @@ prod: node_modules
install:
@source $(ENV_FILE) && \
gem install jekyll bundler && \
mkdir -p $$NVM_DIR && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && \
. $$NVM_DIR/nvm.sh && \
nvm install $(NODE_VERSION) && \
bundle install && \
npm install -g gulp && \
npm install
Expand Down
14 changes: 0 additions & 14 deletions docker-compose-build.yml

This file was deleted.

Loading

0 comments on commit ff5f5a9

Please sign in to comment.