Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup shipyrd-gem Docker image #12

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
5 changes: 5 additions & 0 deletions bin/post-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'shipyrd'

Shipyrd::Client.new.trigger('post-deploy')
5 changes: 5 additions & 0 deletions bin/pre-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'shipyrd'

Shipyrd::Client.new.trigger('pre-build')
5 changes: 5 additions & 0 deletions bin/pre-connect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'shipyrd'

Shipyrd::Client.new.trigger('pre-connect')
5 changes: 5 additions & 0 deletions bin/pre-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'shipyrd'

Shipyrd::Client.new.trigger('pre-deploy')