diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..28977c2 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,55 @@ +name: Docker + +on: + workflow_dispatch: + inputs: + tagInput: + description: 'Tag' + required: true + + release: + types: [created] + tags: + - 'v*' + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Determine version tag + id: version-tag + run: | + INPUT_VALUE="${{ github.event.inputs.tagInput }}" + if [ -z "$INPUT_VALUE" ]; then + INPUT_VALUE="${{ github.ref_name }}" + fi + echo "::set-output name=value::$INPUT_VALUE" + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ghcr.io/shipyrd/shipyrd-gem:latest + ghcr.io/shipyrd/shipyrd-gem:${{ steps.version-tag.outputs.value }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2656ba2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Use the official Ruby 3.3.0 Alpine image as the base image +FROM ruby:3.3.0-alpine + +# Set the working directory to /shipyrd +WORKDIR /shipyrd + +# Copy the Gemfile, shipyrd.gemspec into the container +COPY Gemfile shipyrd.gemspec ./ + +# Required in shipyrd.gemspec +COPY lib/shipyrd/version.rb /shipyrd/lib/shipyrd/version.rb + +# Install system dependencies +RUN apk add --no-cache --update build-base git \ + && gem install bundler --version=2.5.14 \ + && bundle install + +# Copy the rest of our application code into the container. +# We do this after bundle install, to avoid having to run bundle +# every time we do small fixes in the source code. +COPY . . + +# Install the gem locally from the project folder +RUN gem build shipyrd.gemspec && \ + gem install ./shipyrd-*.gem --no-document + +# Set the working directory to /workdir +WORKDIR /workdir + +# Tell git it's safe to access /workdir/.git even if +# the directory is owned by a different user +RUN git config --global --add safe.directory /workdir diff --git a/README.md b/README.md index 1a7176f..bb7cfc7 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,24 @@ If bundler is not being used to manage dependencies, install the gem by executin Please see the main Shipyrd app([https://github.com/shipyrd/shipyrd](https://github.com/shipyrd/shipyrd)) for setup and usage instructions. +## Usage with Docker + +You can run a dockerized version of `shipyrd-gem` by adding the following function to your `~/.bashrc` or similar: + +```bash +shipyrd() { + docker run --rm -v "${PWD}:/workdir" --env-file <(env | grep -E '^(KAMAL_|SHIPYRD_)') ghcr.io/shipyrd/shipyrd-gem /shipyrd/bin/"$@" +} +``` + +Then within a specific Kamal hook (e.g. `pre-connect`), you can call `shipyrd` like this: + +```bash +#!/usr/bin/env bash + +shipyrd pre-connect +``` + ## Recording a deploy This gem currently sends the following deploy details to record a deploy. The various `KAMAL_` ENV variables are set via Kamal when the [hooks are called](https://kamal-deploy.org/docs/hooks/hooks-overview/). diff --git a/bin/post-deploy b/bin/post-deploy new file mode 100755 index 0000000..9c729f0 --- /dev/null +++ b/bin/post-deploy @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require 'shipyrd' + +Shipyrd::Client.new.trigger('post-deploy') diff --git a/bin/pre-build b/bin/pre-build new file mode 100755 index 0000000..5a8c5a0 --- /dev/null +++ b/bin/pre-build @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require 'shipyrd' + +Shipyrd::Client.new.trigger('pre-build') diff --git a/bin/pre-connect b/bin/pre-connect new file mode 100755 index 0000000..a6ec509 --- /dev/null +++ b/bin/pre-connect @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require 'shipyrd' + +Shipyrd::Client.new.trigger('pre-connect') diff --git a/bin/pre-deploy b/bin/pre-deploy new file mode 100755 index 0000000..01107c9 --- /dev/null +++ b/bin/pre-deploy @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require 'shipyrd' + +Shipyrd::Client.new.trigger('pre-deploy')