Skip to content

Commit a4c5428

Browse files
committed
update(gitlab): example for gitlab pipelines
ref: pngmbh/issues#2044
1 parent aeecf7c commit a4c5428

File tree

3 files changed

+330
-0
lines changed

3 files changed

+330
-0
lines changed

.github/workflows/pr.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ jobs:
1414
- run: action-validator ./action.yml
1515
- run: action-validator ./.github/workflows/*
1616

17+
validate-gitlab-template:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v5
21+
- uses: mikefarah/[email protected]
22+
with:
23+
cmd: yq e --exit-status ./gitlab/runway-complete.yml
24+
1725
custom-controller-login:
1826
if: ${{ github.actor != 'dependabot[bot]' }}
1927
needs:

gitlab/README.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Runway GitLab CI Template
2+
3+
This template provides complete Runway CLI setup functionality for GitLab CI/CD pipelines, equivalent to the GitHub Action version.
4+
5+
## Quick Start
6+
7+
1. Include the template in your `.gitlab-ci.yml`:
8+
9+
```yaml
10+
include:
11+
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'
12+
13+
deploy:
14+
extends: .runway-setup
15+
variables:
16+
RUNWAY_USERNAME: $RUNWAY_USER
17+
RUNWAY_PASSWORD: $RUNWAY_PASS
18+
script:
19+
- runway app deploy
20+
```
21+
22+
2. Set required CI/CD variables in your GitLab project:
23+
- `RUNWAY_USER`: Your runway username
24+
- `RUNWAY_PASS`: Your runway password
25+
26+
## Configuration Variables
27+
28+
### Required Variables
29+
30+
| Variable | Description |
31+
|----------|-------------|
32+
| `RUNWAY_USERNAME` | Runway account username |
33+
| `RUNWAY_PASSWORD` | Runway account password |
34+
35+
### Optional Variables
36+
37+
| Variable | Description | Default |
38+
|----------|-------------|---------|
39+
| `RUNWAY_APPLICATION` | Runway application name | `""` |
40+
| `RUNWAY_VERSION` | Runway CLI version | `"latest"` |
41+
| `RUNWAY_LOG_LEVEL` | Log level: debug, info, warn, error | `"error"` |
42+
| `RUNWAY_CONTROLLER_URL` | Custom controller URL | `""` |
43+
| `RUNWAY_ADD_KEY` | Import SSH key: "true" or "false" | `"false"` |
44+
| `RUNWAY_SETUP_SSH` | Setup SSH agent: "true" or "false" | `"false"` |
45+
| `RUNWAY_PRIVATE_KEY` | SSH private key content | `""` |
46+
| `RUNWAY_PUBLIC_KEY` | SSH public key content | `""` |
47+
| `RUNWAY_PUBLIC_KEY_LOCATION` | SSH public key file path | `"~/.ssh/id_rsa.pub"` |
48+
| `RUNWAY_PRIVATE_KEY_LOCATION` | SSH private key file path | `"~/.ssh/id_rsa"` |
49+
50+
## Usage Examples
51+
52+
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.
53+
54+
### Basic Example
55+
56+
```yaml
57+
include:
58+
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'
59+
60+
deploy:
61+
extends: .runway-setup
62+
variables:
63+
RUNWAY_USERNAME: $RUNWAY_USER
64+
RUNWAY_PASSWORD: $RUNWAY_PASS
65+
script:
66+
- runway app ls
67+
rules:
68+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
69+
```
70+
71+
### Deployment (including SSH Setup)
72+
73+
```yaml
74+
include:
75+
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'
76+
77+
deploy:
78+
extends: .runway-setup
79+
variables:
80+
RUNWAY_USERNAME: $RUNWAY_USER
81+
RUNWAY_PASSWORD: $RUNWAY_PASS
82+
RUNWAY_APPLICATION: "my-app"
83+
RUNWAY_SETUP_SSH: "true"
84+
RUNWAY_ADD_KEY: "true"
85+
RUNWAY_PRIVATE_KEY: $SSH_PRIVATE_KEY
86+
RUNWAY_PUBLIC_KEY: $SSH_PUBLIC_KEY
87+
script:
88+
- runway app deploy -a $RUNWAY_APPLICATION
89+
```
90+
91+
### Multi-Stage Pipeline
92+
93+
```yaml
94+
include:
95+
- remote: 'https://raw.githubusercontent.com/your-org/setup-runway/main/gitlab/runway-complete.yml'
96+
97+
stages:
98+
- deploy-staging
99+
- deploy-production
100+
101+
deploy-staging:
102+
stage: deploy-staging
103+
extends: .runway-setup
104+
variables:
105+
RUNWAY_USERNAME: $RUNWAY_USER
106+
RUNWAY_PASSWORD: $RUNWAY_PASS
107+
RUNWAY_APPLICATION: "my-app-staging"
108+
script:
109+
- runway app deploy -a my-app-staging
110+
rules:
111+
- if: $CI_COMMIT_BRANCH == "develop"
112+
113+
deploy-production:
114+
stage: deploy-production
115+
extends: .runway-setup
116+
variables:
117+
RUNWAY_USERNAME: $RUNWAY_USER
118+
RUNWAY_PASSWORD: $RUNWAY_PASS
119+
RUNWAY_APPLICATION: "my-app-prod"
120+
script:
121+
- runway app deploy -a my-app-prod
122+
rules:
123+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
124+
when: manual
125+
```
126+
127+
## Setting Up CI/CD Variables
128+
129+
1. Go to your GitLab project
130+
2. Navigate to Settings → CI/CD → Variables
131+
3. Add the required variables:
132+
- `RUNWAY_USER` (Type: Variable, Masked: Yes)
133+
- `RUNWAY_PASS` (Type: Variable, Masked: Yes)
134+
- `SSH_PRIVATE_KEY` (Type: File, Masked: Yes)
135+
- `SSH_PUBLIC_KEY` (Type: Variable)
136+
137+
## Features
138+
139+
This template provides the same functionality as the GitHub Action:
140+
141+
✅ **CLI Installation**: Downloads and installs runway CLI
142+
✅ **Authentication**: Logs into runway with credentials
143+
✅ **Architecture Detection**: Supports x86_64/amd64 and ARM64 runners
144+
✅ **SSH Key Management**: Optionally sets up SSH keys
145+
✅ **Application Management**: Creates or connects to runway applications
146+
✅ **SSH Agent Setup**: Configures SSH agent for deployments
147+
✅ **Custom Controllers**: Support for enterprise/testing environments
148+
✅ **Version Control**: Specify exact runway CLI versions
149+
150+
## Architecture Support
151+
152+
The template automatically detects runner architecture:
153+
154+
- `x86_64` → `amd64` (Intel/AMD 64-bit)
155+
- `aarch64` → `arm64` (Linux ARM64)
156+
- `arm64` → `arm64` (macOS ARM64)
157+
158+
## Troubleshooting
159+
160+
### Binary Installation Issues
161+
162+
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:
163+
164+
```yaml
165+
script:
166+
- export PATH="$PWD:$PATH"
167+
- runway app deploy
168+
```
169+
170+
### SSH Issues
171+
172+
Ensure your SSH keys are properly formatted in GitLab CI/CD variables:
173+
174+
- Private key should include `-----BEGIN` and `-----END` lines
175+
- Public key should be a single line
176+
177+
### Permission Errors
178+
179+
The template sets proper permissions (0600) on SSH key files automatically.
180+
181+
## Contributing
182+
183+
This template mirrors the functionality of the GitHub Action in `action.yml`. When updating, ensure both remain in sync.

gitlab/runway-complete.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Runway Setup Template for GitLab CI
2+
# Provides complete runway CLI setup functionality
3+
# Usage: include this file and extend .runway-setup in your jobs
4+
5+
.runway-setup:
6+
variables:
7+
# Required variables (must be set by user)
8+
RUNWAY_USERNAME: ""
9+
RUNWAY_PASSWORD: ""
10+
11+
# Optional variables with defaults
12+
RUNWAY_APPLICATION: ""
13+
RUNWAY_VERSION: "latest"
14+
RUNWAY_LOG_LEVEL: "error"
15+
RUNWAY_CONTROLLER_URL: ""
16+
RUNWAY_ADD_KEY: "false"
17+
RUNWAY_SETUP_SSH: "false"
18+
RUNWAY_PRIVATE_KEY: ""
19+
RUNWAY_PUBLIC_KEY: ""
20+
RUNWAY_PUBLIC_KEY_LOCATION: "~/.ssh/id_rsa.pub"
21+
RUNWAY_PRIVATE_KEY_LOCATION: "~/.ssh/id_rsa"
22+
23+
before_script:
24+
# Set custom controller if provided
25+
- |
26+
if [ -n "$RUNWAY_CONTROLLER_URL" ]; then
27+
export RUNWAY_CONTROLLER="$RUNWAY_CONTROLLER_URL"
28+
echo "✅ Set custom controller: $RUNWAY_CONTROLLER_URL"
29+
fi
30+
31+
# Setup SSH keys if provided
32+
- |
33+
if [ -n "$RUNWAY_PRIVATE_KEY" ] && [ -n "$RUNWAY_PUBLIC_KEY" ]; then
34+
mkdir -p ~/.ssh/
35+
echo "$RUNWAY_PRIVATE_KEY" > "$RUNWAY_PRIVATE_KEY_LOCATION"
36+
echo "$RUNWAY_PUBLIC_KEY" > "$RUNWAY_PUBLIC_KEY_LOCATION"
37+
chmod 0600 "$RUNWAY_PRIVATE_KEY_LOCATION"
38+
chmod 0600 "$RUNWAY_PUBLIC_KEY_LOCATION"
39+
echo "✅ SSH keys added"
40+
echo " - public key in $RUNWAY_PUBLIC_KEY_LOCATION"
41+
echo " - private key in $RUNWAY_PRIVATE_KEY_LOCATION"
42+
fi
43+
44+
# Detect architecture and set RUNWAY_ARCH
45+
- |
46+
ARCH=$(uname -m)
47+
case $ARCH in
48+
x86_64) export RUNWAY_ARCH="amd64" ;;
49+
aarch64) export RUNWAY_ARCH="arm64" ;;
50+
arm64) export RUNWAY_ARCH="arm64" ;; # macOS ARM
51+
*) export RUNWAY_ARCH="$ARCH" ;;
52+
esac
53+
echo "Detected architecture: $RUNWAY_ARCH"
54+
55+
# Install runway CLI
56+
- |
57+
echo "Installing runway CLI version $RUNWAY_VERSION..."
58+
curl \
59+
-H 'Cache-Control: no-cache' \
60+
"https://download.runway.horse/runway/$RUNWAY_VERSION/runway_linux_${RUNWAY_ARCH}?nocache=$(date +%s)" \
61+
-o ./runway \
62+
&& chmod +x ./runway
63+
sudo mv ./runway /usr/local/bin/runway || mv ./runway ~/bin/runway || echo "Warning: runway binary placed in current directory"
64+
65+
# Configure runway environment
66+
- |
67+
export RUNWAY_NONINTERACTIVE=true
68+
export RUNWAY_LOGLEVEL="$RUNWAY_LOG_LEVEL"
69+
export RUNWAY_OUTPUT=quiet
70+
71+
# Verify installation
72+
- |
73+
runway -v
74+
echo "✅ Installed Runway CLI"
75+
76+
# Login to runway
77+
- |
78+
if [ -z "$RUNWAY_USERNAME" ] || [ -z "$RUNWAY_PASSWORD" ]; then
79+
echo "❌ Error: RUNWAY_USERNAME and RUNWAY_PASSWORD must be set"
80+
exit 1
81+
fi
82+
runway login -u "$RUNWAY_USERNAME" -p "$RUNWAY_PASSWORD"
83+
echo "✅ Logged in successfully"
84+
85+
# Import SSH key if requested
86+
- |
87+
if [ "$RUNWAY_ADD_KEY" = "true" ]; then
88+
runway key create "$RUNWAY_PUBLIC_KEY_LOCATION"
89+
echo "✅ Imported SSH key"
90+
fi
91+
92+
# Setup or create application if specified
93+
- |
94+
if [ -n "$RUNWAY_APPLICATION" ]; then
95+
if runway app show -a "$RUNWAY_APPLICATION" >/dev/null 2>&1; then
96+
runway gitremote -a "$RUNWAY_APPLICATION"
97+
echo "✅ Attached to application: $RUNWAY_APPLICATION"
98+
else
99+
echo "Application does not exist, creating..."
100+
runway app create -a "$RUNWAY_APPLICATION"
101+
echo "✅ Created new application: $RUNWAY_APPLICATION"
102+
fi
103+
fi
104+
105+
# Setup SSH agent if requested or if keys provided
106+
- |
107+
if [ "$RUNWAY_SETUP_SSH" = "true" ] || ([ -n "$RUNWAY_PRIVATE_KEY" ] && [ -n "$RUNWAY_PUBLIC_KEY" ]); then
108+
export SSH_AUTH_SOCK=/tmp/ssh_agent.sock
109+
ssh-keyscan -p 2222 deploy.runway.horse >> ~/.ssh/known_hosts 2>/dev/null || true
110+
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
111+
ssh-add "$RUNWAY_PRIVATE_KEY_LOCATION"
112+
echo "✅ SSH setup complete"
113+
fi
114+
115+
- echo "🚀 Runway setup complete! Ready to deploy! 🤘"
116+
117+
# Example jobs showing different usage patterns
118+
119+
.runway-deploy-example:
120+
extends: .runway-setup
121+
script:
122+
- runway app deploy
123+
rules:
124+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
125+
126+
.runway-with-ssh-example:
127+
extends: .runway-setup
128+
variables:
129+
RUNWAY_SETUP_SSH: "true"
130+
RUNWAY_ADD_KEY: "true"
131+
script:
132+
- runway app deploy
133+
134+
.runway-with-app-example:
135+
extends: .runway-setup
136+
variables:
137+
RUNWAY_APPLICATION: "my-app"
138+
script:
139+
- runway app deploy -a $RUNWAY_APPLICATION

0 commit comments

Comments
 (0)