From 601264159e5621dfe0c1e3bfdaec3b5e3cf9e2c1 Mon Sep 17 00:00:00 2001 From: paradajz <2544094+paradajz@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:14:04 +0000 Subject: [PATCH] update build infrastructure --- .devcontainer/.git_branch_bash | 24 ++++++++++ .devcontainer/Dockerfile | 53 ---------------------- .devcontainer/Dockerfile.build | 75 +++++++++++++++++++++++++++++++ .devcontainer/Dockerfile.ghcr | 1 + .devcontainer/devcontainer.json | 52 +++++++++++++++------- .github/workflows/deploy.yml | 50 ++++++++++++++------- .github/workflows/docker.yml | 78 ++++++++++++++++++++++++++++----- Gemfile.lock | 6 +-- Makefile | 11 ++--- docker-compose-build.yml | 14 ------ docker-compose.yml | 11 ----- scripts/env_setup.sh | 14 ++++++ 12 files changed, 253 insertions(+), 136 deletions(-) create mode 100644 .devcontainer/.git_branch_bash delete mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/Dockerfile.build create mode 100644 .devcontainer/Dockerfile.ghcr delete mode 100644 docker-compose-build.yml delete mode 100644 docker-compose.yml create mode 100755 scripts/env_setup.sh diff --git a/.devcontainer/.git_branch_bash b/.devcontainer/.git_branch_bash new file mode 100644 index 00000000..b47cce0d --- /dev/null +++ b/.devcontainer/.git_branch_bash @@ -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> " diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index ff3be0cf..00000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM ubuntu:23.04 - -ARG ENV_FILE=/home/ubuntu/.env_setup - -RUN \ -apt-get update && \ -DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ -curl \ -git \ -ca-certificates \ -ruby-full \ -build-essential \ -sudo \ -zlib1g-dev - -# Disable password prompt for sudo commands -RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers - -USER ubuntu -WORKDIR /home/ubuntu - -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 - -# Temporarily add Makefile, Gemfile and NPM package files so that installation is done during -# the container build phase. -ADD \ -Makefile \ -Gemfile \ -Gemfile.lock \ -package.json \ -package-lock.json \ -/home/ubuntu - -RUN \ -sudo chown ubuntu:ubuntu \ -/home/ubuntu/package.json \ -/home/ubuntu/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 - -EXPOSE 3000 \ No newline at end of file diff --git a/.devcontainer/Dockerfile.build b/.devcontainer/Dockerfile.build new file mode 100644 index 00000000..daf7cf15 --- /dev/null +++ b/.devcontainer/Dockerfile.build @@ -0,0 +1,75 @@ +FROM ubuntu:24.04 + +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 \ +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 ${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 \ +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. + +RUN mkdir ${project_dir}/scripts + +COPY \ +Makefile \ +Gemfile \ +Gemfile.lock \ +package.json \ +package-lock.json \ +${project_dir} + +COPY \ +scripts/env_setup.sh \ +${project_dir}/scripts + +RUN \ +sudo chmod 666 \ +Gemfile.lock \ +package-lock.json && \ +make install && \ +rm Makefile \ +Gemfile \ +Gemfile.lock \ +package.json \ +package-lock.json && \ +rm -rf ${project_dir}/scripts + +RUN \ +tee -a /home/ubuntu/.bashrc < 1.0) @@ -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) diff --git a/Makefile b/Makefile index ff133f03..e1a75978 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/docker-compose-build.yml b/docker-compose-build.yml deleted file mode 100644 index fbe29dfd..00000000 --- a/docker-compose-build.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: '3.7' - -services: - shanteacontrols-website: - container_name: shanteacontrols-website - build: - context: . - dockerfile: .devcontainer/Dockerfile - volumes: - - $PWD:/home/ubuntu/website - - $HOME/.ssh:/home/ubuntu/.ssh - hostname: localhost - working_dir: /home/ubuntu/website - command: tail -f /dev/null \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 8cb0bb9f..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: '3.7' - -services: - shanteacontrols-website: - container_name: shanteacontrols-website - image: paradajz168/website-dev - volumes: - - $PWD:/home/ubuntu/website - - $HOME/.ssh:/home/ubuntu/.ssh - working_dir: /home/ubuntu/website - command: tail -f /dev/null \ No newline at end of file diff --git a/scripts/env_setup.sh b/scripts/env_setup.sh new file mode 100755 index 00000000..540b8812 --- /dev/null +++ b/scripts/env_setup.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) +project_root="$(realpath "${script_dir}"/..)" + +export GEM_HOME=$project_root/gems +export GEM_PATH=$project_root/gems +export PATH="$project_root/gems/bin:$PATH" +export NVM_DIR="$HOME/.nvm" + +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + +source ~/.rvm/scripts/rvm +rvm use "$RUBY_VERSION" \ No newline at end of file