Skip to content

Commit

Permalink
rename to install, add urls-map
Browse files Browse the repository at this point in the history
- rename `release-type` to `install`
- add `urls-map` output JSON
  • Loading branch information
Roy Razon committed Dec 21, 2023
1 parent daeedd6 commit 4e8ef36
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 33 deletions.
101 changes: 75 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ The preevy [CLI version](https://www.npmjs.com/package/preevy?activeTab=versions

Optional path to the `docker-compose.yaml` file. If not provided, uses the working directory. If you have multiple docker compose files, you can add them as a comma seperated string like so `'docker-compose.yml,docker-compose.dev.yml'`

### `release-type`
### `install`

*required*: `false`

***EXPERIMENTAL***. Specify `gh-release` to install Preevy from a binary file, which is much faster than using NPM.
***EXPERIMENTAL***. Installation method for the Preevy CLI. Specify `gh-release` to install Preevy from a binary file, which is much faster than using NPM. Specify `none` to skip the installation steps. The default is `npm` which will install from NPM.

If this option is specified, `version` can be either `latest` or one of the [released versions](https://github.com/livecycle/preevy/releases). Canary versions are not supported.
If `gh-release` is specified, `version` can be either `latest` or one of the [released versions](https://github.com/livecycle/preevy/releases). Canary versions are not supported.

### `node-cache`

Expand All @@ -70,9 +70,67 @@ Node package manager used for caching. Supported values: `npm`, `yarn`, `pnpm`,

## Outputs

### `urls-map`

The generated preview environment urls, formatted as a JSON map.

Example (formatted for clarity):

```json
{
"backend": {
"80": "https://backend-80-my-compose-project-demo-pr-abc1234.livecycle.run/",
"9230": "https://backend-9230-my-compose-project-demo-pr-abc1234.livecycle.run/"
},
"frontend": {
"3000": "https://frontend-my-compose-project-demo-pr-abc1234.livecycle.run/"
}
}
```

The URL for a specific service and port can be expressed in the job as

```
${{ fromJson(steps.STEP_ID.outputs.urls-map).SERVICE_NAME[PORT] }}
```

For example:

```
${{ fromJson(steps.preevy.outputs.urls-map).frontend[3000] }}
```

See examples below.

### `urls-json`

The generated preview environment urls, formatted in JSON.
The generated preview environment URLs, formatted as a JSON array.

Example (formatted for clarity):

```json
[
{
"project": "my-compose-project",
"service": "frontend",
"port": 3000,
"url": "https://frontend-my-compose-project-demo-pr-abc1234.livecycle.run/"
},
{
"project": "my-compose-project",
"service": "backend",
"port": 80,
"url": "https://backend-80-my-compose-project-demo-pr-abc1234.livecycle.run/"
},
{
"project": "my-compose-project",
"service": "backend",
"port": 9230,
"url": "https://backend-9230-my-compose-project-demo-pr-abc1234.livecycle.run/"
}
]
```


## Examples

Expand Down Expand Up @@ -105,10 +163,10 @@ jobs:
concurrency: preevy-${{ github.event.number }}

environment:
# An environment needs to be created at
# https://github.com/YOUR-ORG/YOUR-REPO/settings/environments
# An environment needs to be created at https://github.com/YOUR-ORG/YOUR-REPO/settings/environments
name: preview
url: ${{ steps.store_url.outputs.url }}
# Change `frontend` and `3000` to the service and port whos URL should be used for the deployment
url: ${{ fromJson(steps.preevy.outputs.urls-map).frontend[3000] }}

runs-on: ubuntu-latest
steps:
Expand All @@ -122,17 +180,11 @@ jobs:
- uses: livecycle/[email protected]
id: preevy
with:
# Create the profile using the `preevy init` command, see
# https://preevy.dev/ci/overview
# Create the profile using the `preevy init` command, see https://preevy.dev/ci
profile-url: "s3://preevy-12345678-my-profile?region=eu-west-1"
# Only required if the Compose file(s) are not in the default locations
# https://docs.docker.com/compose/reference/#specifying-multiple-compose-files
docker-compose-yaml-paths: "./docker/docker-compose.yaml"

# Change `frontend` and `3000` in this step to your main service and port
# This will appear as the GH environment URL
- id: store_url
name: Store URL of frontend
run: |
echo url=$(jq -r '.[] | select(.service=="frontend" and .port==3000).url' "${{ steps.preevy_up.outputs.urls-file }}") >> "$GITHUB_OUTPUT"
```
### Build on the CI machine with cache, deploy on a Google Cloud VM
Expand Down Expand Up @@ -166,8 +218,10 @@ jobs:
concurrency: preevy-${{ github.event.number }}

environment:
# An environment needs to be created at https://github.com/YOUR-ORG/YOUR-REPO/settings/environments
name: preview
url: ${{ steps.store_url.outputs.url }}
# Change `frontend` and `3000` to the service and port whos URL should be used for the deployment
url: ${{ fromJson(steps.preevy.outputs.urls-map).frontend[3000] }}

env:
GITHUB_TOKEN: ${{ github.token }}
Expand Down Expand Up @@ -200,17 +254,12 @@ jobs:
- uses: livecycle/[email protected]
id: preevy_up
with:
# Create the profile using the `preevy init` command, see
# https://preevy.dev/ci/overview
# Create the profile using the `preevy init` command, see https://preevy.dev/ci
profile-url: "s3://preevy-12345678-my-profile?region=eu-west-1"
# Specify the GHCR registry and the builder created above
args: --registry ghcr.io/livecycle --builder ${{ steps.buildx_setup.outputs.name }}

# Change `frontend` and `3000` in this step to your main service and port
# This will appear as the GH environment URL
- id: store_url
name: Store URL of frontend
run: |
echo url=$(jq -r '.[] | select(.service=="frontend" and .port==3000).url' "${{ steps.preevy_up.outputs.urls-file }}") >> "$GITHUB_OUTPUT"
# Only required if the Compose file(s) are not in the default locations
# https://docs.docker.com/compose/reference/#specifying-multiple-compose-files
docker-compose-yaml-paths: "./docker/docker-compose.yaml"

```
26 changes: 19 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,34 @@ inputs:
required: false
description: "Node package manager used for caching. Supported values: npm, yarn, pnpm, or ''. See https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-data"
default: npm
release-type:
install:
required: false
description: "EXPERIMENTAL: Type of release to use. Supported values: npm, gh-release"
description: "EXPERIMENTAL: Installation method of the Preevy CLI. Supported values: npm, gh-release or none"
default: npm
outputs:
urls-map:
description: "The generated URLs of the preview environments created by Preevy, formatted as a JSON map of <service>.<port>.<url>"
value: ${{ steps.run_preevy.outputs.urls-map }}
urls-json:
description: "The generated URLs of the preview environments create by Preevy, formatted as a JSON object"
description: "The generated URLs of the preview environments created by Preevy, formatted as a JSON array"
value: ${{ steps.run_preevy.outputs.urls-json }}
urls-file:
description: "Path to file containing the generated URLs of the preview environments create by Preevy, formatted as a JSON object"
description: "Path to file containing the generated URLs of the preview environments create by Preevy, formatted as a JSON array"
value: ${{ steps.run_preevy.outputs.urls-file }}
runs:
using: "composite"
steps:
-
uses: actions/setup-node@v4
if: ${{ inputs.release-type == 'npm' }}
if: ${{ inputs.install == 'npm' }}
with:
node-version: 18
cache: ${{ inputs.node-cache }}

- name: Install Preevy from GH release
shell: bash
id: install_prevy_gh_release
if: ${{ inputs.release-type == 'gh-release' }}
if: ${{ inputs.install == 'gh-release' }}
run: |
set -eou pipefail
Expand Down Expand Up @@ -87,15 +90,24 @@ runs:
urls_file=${RUNNER_TEMP}/preevy_urls.${RANDOM}.json
if [[ "${{ inputs.release-type }}" == "npm" ]]; then
if [[ "${{ inputs.install }}" == "npm" ]]; then
preevy_cmd="npx -- preevy@${{ inputs.version }}"
else
preevy_cmd=preevy
fi
${preevy_cmd} up ${opts} --profile '${{ inputs.profile-url }}' --output-urls-to ${urls_file} ${{ inputs.args }}
echo Raw URLs JSON
cat ${urls_file}
echo "urls-json=$(cat ${urls_file})" >> $GITHUB_OUTPUT
echo "urls-file=${urls_file}" >> $GITHUB_OUTPUT
urls_map=$(cat ${urls_file} | jq -c 'group_by(.service) | map({ (.[0].service): (map({ (.port|tostring): .url })) | add }) | add')
echo ""
echo URLs map
echo "${urls_map}"
echo "urls-map=${urls_map}" >> $GITHUB_OUTPUT

0 comments on commit 4e8ef36

Please sign in to comment.