From bad233f141420a3b0c5963f38d6db58170736876 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Thu, 18 Apr 2024 13:59:38 -0700 Subject: [PATCH] fix: push what I have --- .githooks/commit-msg | 4 ++ .githooks/pre-commit | 10 ++++ .github/workflows/pull_request.yml | 77 ++++++++++++++++++++++++++++++ .github/workflows/push_main.yml | 29 +++++++++++ .github/workflows/upload_image.yml | 47 ++++++++++++++++++ .releaserc | 10 ++++ Dockerfile | 14 ++++++ Makefile | 14 ++++++ commitlint.config.js | 6 +++ docker-compose.yml | 7 +++ scripts/aurlist.txt | 8 ++++ scripts/configure.sh | 7 +++ scripts/install_packages.sh | 37 ++++++++++++++ scripts/modify_shell.sh | 7 +++ scripts/pkglist.txt | 6 +++ 15 files changed, 283 insertions(+) create mode 100755 .githooks/commit-msg create mode 100755 .githooks/pre-commit create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/push_main.yml create mode 100644 .github/workflows/upload_image.yml create mode 100644 .releaserc create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 commitlint.config.js create mode 100644 docker-compose.yml create mode 100644 scripts/aurlist.txt create mode 100755 scripts/configure.sh create mode 100755 scripts/install_packages.sh create mode 100755 scripts/modify_shell.sh create mode 100644 scripts/pkglist.txt diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 0000000..6fd2a1e --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "running commitlint against git history" +npx -p @commitlint/config-conventional -p @commitlint/cli -c "cat $1 | commitlint" diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..e82ef47 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "running yamllint against repository" +yamllint . + +echo "running hadolint against Dockerfile" +hadolint Dockerfile + +echo "running shellcheck against repository" +shellcheck scripts/**.sh -f gcc diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..c57f64e --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,77 @@ +--- +on: [pull_request] # yamllint disable-line rule:truthy +name: main +jobs: + + commitlint: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - run: npm install --save-dev @commitlint/{config-conventional,cli} + - run: npx commitlint --from=${{ github.event.pull_request.base.sha }} + + golangci-lint: + strategy: + matrix: + go-version: [1.20.x] + os: [ubuntu-latest, macos-latest] + name: lint + runs-on: ${{ matrix.os }} + steps: + + - uses: actions/checkout@v3 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.51.1 + + yamllint: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: yaml-lint + uses: ibiqlik/action-yamllint@v3 + + hadolint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: hadolint/hadolint-action@v2.0.0 + with: + dockerfile: Dockerfile + + test: + strategy: + matrix: + go-version: [1.20.x] + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Test + run: go test ./... diff --git a/.github/workflows/push_main.yml b/.github/workflows/push_main.yml new file mode 100644 index 0000000..a2d130c --- /dev/null +++ b/.github/workflows/push_main.yml @@ -0,0 +1,29 @@ +--- +name: Release Version + +on: # yamllint disable-line rule:truthy + push: + branches: + - main + +jobs: + release: + name: 'Release to GitHub' + runs-on: ubuntu-latest + steps: + + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: lts/* + + - name: Install Semantic Release Plugins + run: npm install --save-dev @semantic-release/changelog @semantic-release/git conventional-changelog-conventionalcommits # yamllint disable-line rule:line-length + + - name: Release Version + env: + GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }} + run: npx semantic-release diff --git a/.github/workflows/upload_image.yml b/.github/workflows/upload_image.yml new file mode 100644 index 0000000..fdea7b6 --- /dev/null +++ b/.github/workflows/upload_image.yml @@ -0,0 +1,47 @@ +--- +name: Upload Image + +on: # yamllint disable-line rule:truthy + release: + types: + - created + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..098c3a2 --- /dev/null +++ b/.releaserc @@ -0,0 +1,10 @@ +--- +branches: +- master +- main +plugins: +- - "@semantic-release/commit-analyzer" + - preset: conventionalcommits +- - "@semantic-release/release-notes-generator" + - preset: conventionalcommits +- - "@semantic-release/github" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..545739f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# archlinux is rolling release, not specifying version +# hadolint ignore=DL3006 +FROM --platform=$BUILDPLATFORM archlinux as stage1 + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +COPY scripts/ /scripts/ +RUN /scripts/configure.sh + +FROM stage1 as stage2 +RUN /scripts/install_packages.sh + +FROM stage2 as stage3 +RUN /scripts/modify_shell.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..46f826c --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +# Makefile +all: setup hooks + +# requires `nvm use --lts` or `nvm use node` +.PHONY: setup +setup: + npm install -g @commitlint/config-conventional @commitlint/cli + brew install hadolint + brew install shellcheck + + +.PHONY: hooks +hooks: + @git config --local core.hooksPath .githooks/ \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..8104eb1 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,6 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + ignores: [ + (message) => message.includes('Initial commit') + ], + }; \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..33c1edb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +--- +version: "3.3" + +services: + konnect: + build: . + command: sleep infinity \ No newline at end of file diff --git a/scripts/aurlist.txt b/scripts/aurlist.txt new file mode 100644 index 0000000..d190c8e --- /dev/null +++ b/scripts/aurlist.txt @@ -0,0 +1,8 @@ +zsh +inetutils +redis +mariadb +clickhouse +mongosh-bin +google-cloud-cli +croc \ No newline at end of file diff --git a/scripts/configure.sh b/scripts/configure.sh new file mode 100755 index 0000000..050bdc1 --- /dev/null +++ b/scripts/configure.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Address Security Concerns +pacman-key --init + +# Update All Packages +pacman -Syu --noconfirm \ No newline at end of file diff --git a/scripts/install_packages.sh b/scripts/install_packages.sh new file mode 100755 index 0000000..0aa108b --- /dev/null +++ b/scripts/install_packages.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Install packages from pkglist.txt +pacman -S --needed --noconfirm - < scripts/pkglist.txt + +# Yay temporary build directory and user creation +mkdir -p /tmp/yay-build +useradd -m -G wheel builder && passwd -d builder +chown -R builder:builder /tmp/yay-build +echo 'builder ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers + +# Install yay +su - builder -c "git clone https://aur.archlinux.org/yay.git /tmp/yay-build/yay" +su - builder -c "cd /tmp/yay-build/yay && makepkg -si --noconfirm" + +# Remove yay temporary build directory +# rm -rf /tmp/yay-build + +# Add non-root user captain +# useradd -m -G wheel captain && passwd -d captain + +# Install packages from aurlist.txt +yay -S --noconfirm - < /scripts/aurlist.txt + +# Install evans +unamestr=$(uname -m) +if [ "$unamestr" = "x86_64" ]; then + curl -sSLO https://github.com/ktr0731/evans/releases/download/v0.10.11/evans_linux_amd64.tar.gz + tar -xvzf evans_linux_amd64.tar.gz + mv evans /usr/local/bin + rm -rf evans_linux_amd64.tar.gz +elif [ "$unamestr" = "aarch64" ] || [ $unamestr = "arm64" ]; then + curl -sSLO https://github.com/ktr0731/evans/releases/download/v0.10.11/evans_linux_arm64.tar.gz + tar -xvzf evans_linux_arm64.tar.gz + mv evans /usr/local/bin + rm -rf evans_linux_arm64.tar.gz +fi \ No newline at end of file diff --git a/scripts/modify_shell.sh b/scripts/modify_shell.sh new file mode 100755 index 0000000..d39cafa --- /dev/null +++ b/scripts/modify_shell.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Change default shell to zsh +chsh -s /bin/zsh + +# Install oh-my-zsh +sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \ No newline at end of file diff --git a/scripts/pkglist.txt b/scripts/pkglist.txt new file mode 100644 index 0000000..07125fc --- /dev/null +++ b/scripts/pkglist.txt @@ -0,0 +1,6 @@ +base +base-devel +git +sudo +go +coreutils \ No newline at end of file