Skip to content
Draft
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
8 changes: 8 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jobs:
- run: action-validator ./action.yml
- run: action-validator ./.github/workflows/*

validate-gitlab-template:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: mikefarah/[email protected]
with:
cmd: yq e --exit-status ./gitlab/runway-complete.yml

custom-controller-login:
if: ${{ github.actor != 'dependabot[bot]' }}
needs:
Expand Down
183 changes: 183 additions & 0 deletions gitlab/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# Runway GitLab CI Template

This template provides complete Runway CLI setup functionality for GitLab CI/CD pipelines, equivalent to the GitHub Action version.

## Quick Start

1. Include the template in your `.gitlab-ci.yml`:

```yaml
include:
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'

deploy:
extends: .runway-setup
variables:
RUNWAY_USERNAME: $RUNWAY_USER
RUNWAY_PASSWORD: $RUNWAY_PASS
script:
- runway app deploy
```

2. Set required CI/CD variables in your GitLab project:
- `RUNWAY_USER`: Your runway username
- `RUNWAY_PASS`: Your runway password

## Configuration Variables

### Required Variables

| Variable | Description |
|----------|-------------|
| `RUNWAY_USERNAME` | Runway account username |
| `RUNWAY_PASSWORD` | Runway account password |

### Optional Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `RUNWAY_APPLICATION` | Runway application name | `""` |
| `RUNWAY_VERSION` | Runway CLI version | `"latest"` |
| `RUNWAY_LOG_LEVEL` | Log level: debug, info, warn, error | `"error"` |
| `RUNWAY_CONTROLLER_URL` | Custom controller URL | `""` |
| `RUNWAY_ADD_KEY` | Import SSH key: "true" or "false" | `"false"` |
| `RUNWAY_SETUP_SSH` | Setup SSH agent: "true" or "false" | `"false"` |
| `RUNWAY_PRIVATE_KEY` | SSH private key content | `""` |
| `RUNWAY_PUBLIC_KEY` | SSH public key content | `""` |
| `RUNWAY_PUBLIC_KEY_LOCATION` | SSH public key file path | `"~/.ssh/id_rsa.pub"` |
| `RUNWAY_PRIVATE_KEY_LOCATION` | SSH private key file path | `"~/.ssh/id_rsa"` |

## Usage Examples

Please note that any deployment requires your SSH key. But you can set them up yourself if you don't want us to paste them into place and set permissions.

### Basic Example

```yaml
include:
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'

deploy:
extends: .runway-setup
variables:
RUNWAY_USERNAME: $RUNWAY_USER
RUNWAY_PASSWORD: $RUNWAY_PASS
script:
- runway app ls
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
```

### Deployment (including SSH Setup)

```yaml
include:
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'

deploy:
extends: .runway-setup
variables:
RUNWAY_USERNAME: $RUNWAY_USER
RUNWAY_PASSWORD: $RUNWAY_PASS
RUNWAY_APPLICATION: "my-app"
RUNWAY_SETUP_SSH: "true"
RUNWAY_ADD_KEY: "true"
RUNWAY_PRIVATE_KEY: $SSH_PRIVATE_KEY
RUNWAY_PUBLIC_KEY: $SSH_PUBLIC_KEY
script:
- runway app deploy -a $RUNWAY_APPLICATION
```

### Multi-Stage Pipeline

```yaml
include:
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'

stages:
- deploy-staging
- deploy-production

deploy-staging:
stage: deploy-staging
extends: .runway-setup
variables:
RUNWAY_USERNAME: $RUNWAY_USER
RUNWAY_PASSWORD: $RUNWAY_PASS
RUNWAY_APPLICATION: "my-app-staging"
script:
- runway app deploy -a my-app-staging
rules:
- if: $CI_COMMIT_BRANCH == "develop"

deploy-production:
stage: deploy-production
extends: .runway-setup
variables:
RUNWAY_USERNAME: $RUNWAY_USER
RUNWAY_PASSWORD: $RUNWAY_PASS
RUNWAY_APPLICATION: "my-app-prod"
script:
- runway app deploy -a my-app-prod
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
```

## Setting Up CI/CD Variables

1. Go to your GitLab project
2. Navigate to Settings → CI/CD → Variables
3. Add the required variables:
- `RUNWAY_USER` (Type: Variable, Masked: Yes)
- `RUNWAY_PASS` (Type: Variable, Masked: Yes)
- `SSH_PRIVATE_KEY` (Type: File, Masked: Yes)
- `SSH_PUBLIC_KEY` (Type: Variable)

## Features

This template provides the same functionality as the GitHub Action:

✅ **CLI Installation**: Downloads and installs runway CLI
✅ **Authentication**: Logs into runway with credentials
✅ **Architecture Detection**: Supports x86_64/amd64 and ARM64 runners
✅ **SSH Key Management**: Optionally sets up SSH keys
✅ **Application Management**: Creates or connects to runway applications
✅ **SSH Agent Setup**: Configures SSH agent for deployments
✅ **Custom Controllers**: Support for enterprise/testing environments
✅ **Version Control**: Specify exact runway CLI versions

## Architecture Support

The template automatically detects runner architecture:

- `x86_64` → `amd64` (Intel/AMD 64-bit)
- `aarch64` → `arm64` (Linux ARM64)
- `arm64` → `arm64` (macOS ARM64)

## Troubleshooting

### Binary Installation Issues

If the runway binary can't be moved to `/usr/local/bin`, the template will try `~/bin` or place it in the current directory. Ensure your GitLab runner has appropriate permissions or add the current directory to PATH:

```yaml
script:
- export PATH="$PWD:$PATH"
- runway app deploy
```

### SSH Issues

Ensure your SSH keys are properly formatted in GitLab CI/CD variables:

- Private key should include `-----BEGIN` and `-----END` lines
- Public key should be a single line

### Permission Errors

The template sets proper permissions (0600) on SSH key files automatically.

## Contributing

This template mirrors the functionality of the GitHub Action in `action.yml`. When updating, ensure both remain in sync.
139 changes: 139 additions & 0 deletions gitlab/runway-complete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Runway Setup Template for GitLab CI
# Provides complete runway CLI setup functionality
# Usage: include this file and extend .runway-setup in your jobs

.runway-setup:
variables:
# Required variables (must be set by user)
RUNWAY_USERNAME: ""
RUNWAY_PASSWORD: ""

# Optional variables with defaults
RUNWAY_APPLICATION: ""
RUNWAY_VERSION: "latest"
RUNWAY_LOG_LEVEL: "error"
RUNWAY_CONTROLLER_URL: ""
RUNWAY_ADD_KEY: "false"
RUNWAY_SETUP_SSH: "false"
RUNWAY_PRIVATE_KEY: ""
RUNWAY_PUBLIC_KEY: ""
RUNWAY_PUBLIC_KEY_LOCATION: "~/.ssh/id_rsa.pub"
RUNWAY_PRIVATE_KEY_LOCATION: "~/.ssh/id_rsa"

before_script:
# Set custom controller if provided
- |
if [ -n "$RUNWAY_CONTROLLER_URL" ]; then
export RUNWAY_CONTROLLER="$RUNWAY_CONTROLLER_URL"
echo "✅ Set custom controller: $RUNWAY_CONTROLLER_URL"
fi

# Setup SSH keys if provided
- |
if [ -n "$RUNWAY_PRIVATE_KEY" ] && [ -n "$RUNWAY_PUBLIC_KEY" ]; then
mkdir -p ~/.ssh/
echo "$RUNWAY_PRIVATE_KEY" > "$RUNWAY_PRIVATE_KEY_LOCATION"
echo "$RUNWAY_PUBLIC_KEY" > "$RUNWAY_PUBLIC_KEY_LOCATION"
chmod 0600 "$RUNWAY_PRIVATE_KEY_LOCATION"
chmod 0600 "$RUNWAY_PUBLIC_KEY_LOCATION"
echo "✅ SSH keys added"
echo " - public key in $RUNWAY_PUBLIC_KEY_LOCATION"
echo " - private key in $RUNWAY_PRIVATE_KEY_LOCATION"
fi

# Detect architecture and set RUNWAY_ARCH
- |
ARCH=$(uname -m)
case $ARCH in
x86_64) export RUNWAY_ARCH="amd64" ;;
aarch64) export RUNWAY_ARCH="arm64" ;;
arm64) export RUNWAY_ARCH="arm64" ;; # macOS ARM
*) export RUNWAY_ARCH="$ARCH" ;;
esac
echo "Detected architecture: $RUNWAY_ARCH"

# Install runway CLI
- |
echo "Installing runway CLI version $RUNWAY_VERSION..."
curl \
-H 'Cache-Control: no-cache' \
"https://download.runway.horse/runway/$RUNWAY_VERSION/runway_linux_${RUNWAY_ARCH}?nocache=$(date +%s)" \
-o ./runway \
&& chmod +x ./runway
sudo mv ./runway /usr/local/bin/runway || mv ./runway ~/bin/runway || echo "Warning: runway binary placed in current directory"

# Configure runway environment
- |
export RUNWAY_NONINTERACTIVE=true
export RUNWAY_LOGLEVEL="$RUNWAY_LOG_LEVEL"
export RUNWAY_OUTPUT=quiet

# Verify installation
- |
runway -v
echo "✅ Installed Runway CLI"

# Login to runway
- |
if [ -z "$RUNWAY_USERNAME" ] || [ -z "$RUNWAY_PASSWORD" ]; then
echo "❌ Error: RUNWAY_USERNAME and RUNWAY_PASSWORD must be set"
exit 1
fi
runway login -u "$RUNWAY_USERNAME" -p "$RUNWAY_PASSWORD"
echo "✅ Logged in successfully"

# Import SSH key if requested
- |
if [ "$RUNWAY_ADD_KEY" = "true" ]; then
runway key create "$RUNWAY_PUBLIC_KEY_LOCATION"
echo "✅ Imported SSH key"
fi

# Setup or create application if specified
- |
if [ -n "$RUNWAY_APPLICATION" ]; then
if runway app show -a "$RUNWAY_APPLICATION" >/dev/null 2>&1; then
runway gitremote -a "$RUNWAY_APPLICATION"
echo "✅ Attached to application: $RUNWAY_APPLICATION"
else
echo "Application does not exist, creating..."
runway app create -a "$RUNWAY_APPLICATION"
echo "✅ Created new application: $RUNWAY_APPLICATION"
fi
fi

# Setup SSH agent if requested or if keys provided
- |
if [ "$RUNWAY_SETUP_SSH" = "true" ] || ([ -n "$RUNWAY_PRIVATE_KEY" ] && [ -n "$RUNWAY_PUBLIC_KEY" ]); then
export SSH_AUTH_SOCK=/tmp/ssh_agent.sock
ssh-keyscan -p 2222 deploy.runway.horse >> ~/.ssh/known_hosts 2>/dev/null || true
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add "$RUNWAY_PRIVATE_KEY_LOCATION"
echo "✅ SSH setup complete"
fi

- echo "🚀 Runway setup complete! Ready to deploy! 🤘"

# Example jobs showing different usage patterns

.runway-deploy-example:
extends: .runway-setup
script:
- runway app deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

.runway-with-ssh-example:
extends: .runway-setup
variables:
RUNWAY_SETUP_SSH: "true"
RUNWAY_ADD_KEY: "true"
script:
- runway app deploy

.runway-with-app-example:
extends: .runway-setup
variables:
RUNWAY_APPLICATION: "my-app"
script:
- runway app deploy -a $RUNWAY_APPLICATION
Loading