Skip to content

Commit

Permalink
Adds action code
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Feb 22, 2024
1 parent 1d1dac9 commit 428fb29
Show file tree
Hide file tree
Showing 6 changed files with 559 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use the uselagoon/lagoon-cli as a base image
# FROM uselagoon/lagoon-cli as base
FROM ghcr.io/uselagoon/lagoon-cli:main as base


RUN apk update && apk upgrade && apk add python3 py3-pip

# Grab envplate so we can sort out the configuration files
RUN wget -q https://github.com/kreuzwerker/envplate/releases/download/v1.0.2/envplate_1.0.2_$(uname -s)_$(uname -m).tar.gz -O - | tar xz && mv envplate /usr/local/bin/ep && chmod +x /usr/local/bin/ep

# Copy the entry script and set correct permissions
COPY entry.sh /entry.sh
COPY action.py /action.py
RUN chmod +x /entry.sh

# copy across the lagoon.yaml file
COPY lagoon.yml /rootcp/.lagoon.yml

# let's set up a symlink to the lagoon cli into the /usr/local/bin directory
RUN ln -s /lagoon /usr/local/bin/lagoon

# Set up environment variable for the SSH key
ENV INPUT_SSH_PRIVATE_KEY ""
ENV INPUT_LAGOON_GRAPHQL_ENDPOINT "https://api.lagoon.amazeeio.cloud/graphql"
ENV INPUT_LAGOON_SSH_HOSTNAME "ssh.lagoon.amazeeio.cloud"
ENV INPUT_LAGOON_PORT "32222"
ENV INPUT_LAGOON_COMMAND "whoami"

WORKDIR /

# Entry point to run the custom script
ENTRYPOINT ["/entry.sh"]
185 changes: 185 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Lagoon Action

This action interacts with the Lagoon API to allow you to currently
* Create and deploy environments based on Branch name or PR
* Upsert project/environment variables

## Requirements

To use this GitHub Action, you'll need to set up the following:

### GitHub Action Secret

* You will want to contact your Lagoon API administrator to set up a user with the [developer role](https://docs.lagoon.sh/concepts-basics/building-blocks/roles/) on the project you're going to be interacting with using this action.
* You should then add an SSH key to this user's account that will _only_ be used by this action.
* Create a secret in your GitHub repository that contains the private SSH key for authenticating with Lagoon. To add a secret:

- Navigate to your GitHub repository.
- Go to the "Settings" tab.
- In the left sidebar, click on "Secrets and Variables"
- Click on "Actions".
- Click on "New repository secret."
- Name the secret, e.g., `LAGOON_SSH_PRIVATE_KEY`.
- Paste the contents of your private SSH key into the "Value" field.
- Click on "Add secret."

## Inputs

### General

#### `action`

**Description:** One of the following actions: deploy (default), upsert_variable.

**Required:** Yes

**Default:** 'deploy'

#### `ssh_private_key`

**Description:** SSH private key for Lagoon authentication.

**Required:** Yes

#### `lagoon_graphql_endpoint`

**Description:** Lagoon GraphQL endpoint.

**Required:** No

**Default:** https://api.lagoon.amazeeio.cloud/graphql

#### `lagoon_ssh_hostname`

**Description:** Lagoon SSH hostname.

**Required:** No

**Default:** ssh.lagoon.amazeeio.cloud

#### `lagoon_port`

**Description:** Lagoon SSH port.

**Required:** No

**Default:** 32222

#### `lagoon_project`

**Description:** Lagoon project name.

**Required:** No

#### `lagoon_environment`

**Description:** Lagoon environment name.

**Required:** No

#### `debug`

**Description:** Enable debug output.

**Required:** No

**Default:** false



### Action: deploy

#### `wait_for_deployment`

**Description:** Wait for deployment to finish.

**Action:** `deploy`

**Required:** No

**Default:** false

#### `max_deployment_timeout`

**Description:** Maximum time (minutes) to wait for deployment - defaults to 30 minutes.

**Required:** No

**Action:** `deploy`

**Default:** 30

### Action: upsert_variable

#### `variable_scope`

**Description:** If action is upsert_variable, this is the variable scope (runtime, build).

**Required:** For `upsert_variable`

**Action:** `upsert_variable`

**Default:** 'runtime'

#### `variable_name`

**Description:** If action is upsert_variable, this is the variable name.

**Required:** For `upsert_variable`

**Action:** `upsert_variable`

#### `variable_value`

**Description:** If action is upsert_variable, this is the variable value.

**Required:** For `upsert_variable`

**Action:** `upsert_variable`


## Example Usage

```yaml
name: Lagoon Deployment

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Lagoon Deployment
uses: uselagoon/lagoon-action@v1
with:
action: 'deploy'
ssh_private_key: ${{ secrets.LAGOON_SSH_PRIVATE_KEY }}
lagoon_project: 'your-project-name'
lagoon_environment: 'your-environment-name'
wait_for_deployment: 'true'

upsert-variable:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Lagoon Upsert Variable
uses: uselagoon/lagoon-action@v1
with:
action: 'upsert_variable'
ssh_private_key: ${{ secrets.LAGOON_SSH_PRIVATE_KEY }}
lagoon_project: 'your-project-name'
lagoon_environment: 'your-environment-name'
variable_scope: 'runtime'
variable_name: 'your-variable-name'
variable_value: 'your-variable-value'

Loading

0 comments on commit 428fb29

Please sign in to comment.