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

Setup shipyrd-gem Docker image #12

merged 3 commits into from
Jul 8, 2024

Conversation

AliOsm
Copy link
Contributor

@AliOsm AliOsm commented Jun 21, 2024

What?

This PR sets up a Docker image for the shipyrd-gem gem.

Why?

To enable non-Ruby projects using Kamal as a deployment tool to benefit from Shipyrd without needing to install Ruby in their development environment.

How?

  • Workflow: The PR adapts Kamal's docker-publish.yml workflow, only changing the repository name. Note that a new image will be generated on each release.

  • Dockerfile: A simplified Kamal Dockerfile is created, removing Docker and SSH dependencies, and excluding an entry point.

  • Scripts: 4 new scripts are added to the ./bin directory to run Shipyrd triggers. Users should add the following line to each Kamal hook supported by Shipyrd:

    docker run --rm -v "${PWD}:/workdir" --env-file <(env | grep -E '^(KAMAL_|SHIPYRD_)') 
    ghcr.io/shipyrd/shipyrd-gem:latest /shipyrd/bin/$(basename $0)
    • -v "${PWD}:/workdir": Binds the current directory to /workdir to access the latest commit message.
    • --env-file <(env | grep -E '^(KAMAL_|SHIPYRD_)'): Passes Kamal and Shipyrd environment variables to the shipyrd-gem container.
    • $(basename $0): Generalizes the command to be hook agnostic.

Testing

Tested on a Ruby on Rails project using a standard terminal and a DevContainer (within Docker). It is working fine. The shipyrd-gem image used for testing is available here.

Limitations

The shipyrd-gem container can't access the gh CLI to retrieve the GitHub username.

Next steps

Post-approval, the repository owner should create a repository secret named GH_TOKEN with a GitHub personal access token that has write:packages permission. No need for this step, I just knew about secrets.GITHUB_TOKEN being predefined in GitHub Actions.

Also, the main Shipyrd repository documentation should be updated.

Enhancements

  • Consolidate the 4 scripts in ./bin into 1 script with an argument variable.
  • Explore ways to reduce the Docker image size.

@AliOsm
Copy link
Contributor Author

AliOsm commented Jun 21, 2024

Closes #11

@AliOsm
Copy link
Contributor Author

AliOsm commented Jun 23, 2024

Hello @nickhammond, could you please take a look into the PR?

@nickhammond
Copy link
Collaborator

Hey @AliOsm - Thanks for opening this PR, I'll take a look at it this week!

@AliOsm
Copy link
Contributor Author

AliOsm commented Jun 30, 2024

Hello @nickhammond, any updates on this?

@nickhammond
Copy link
Collaborator

Hey @AliOsm - Nice work! Can you help update the readme with some of the details from your scripts section?

Thinking we can help users out with a function:

MacOS:

shipyrd() {
  docker run --platform linux/arm64 --rm -v "${PWD}:/workdir"  --env-file <(env | grep -E '^(KAMAL_|SHIPYRD_)') ghcr.io/shipyrd/shipyrd-gem:latest /shipyrd/bin/"$@"
}

Linux:
Just removing the platform

shipyrd() {
  docker run  --rm -v "${PWD}:/workdir"  --env-file <(env | grep -E '^(KAMAL_|SHIPYRD_)') ghcr.io/shipyrd/shipyrd-gem:latest /shipyrd/bin/"$@"
}

Then within .kamal/hooks/* or .kamal/hooks/pre-connect we just need:

#!/usr/bin/env zsh
shipyrd pre-connect

@AliOsm
Copy link
Contributor Author

AliOsm commented Jul 3, 2024

Hello @nickhammond, sure.

For MacOS vs Linux commands, docker can detect the required platform automatically and download the right image, so no need for different functions.

@nickhammond
Copy link
Collaborator

@AliOsm This is great, I'll get a release cut next week with this, thank you!

@nickhammond nickhammond merged commit 6fe49fa into Shipyrd:main Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants