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

feat: initial commit #1

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
33 changes: 33 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: pr

on:
pull_request:
types:
- opened
- edited
- synchronize

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Molnctl Setup
uses: molnett/setup-molnctl-action@v2
with:
api-token-client-id: ${{ secrets.MOLNETT_CLIENT_ID }}
api-token-client-secret: ${{ secrets.MOLNETT_CLIENT_SECRET }}
default-org: personal
- name: Deploy Ephemeral Environment
uses: ./
with:
action: deploy
manifest-path: test/molnett.yaml
- name: Delete Ephemeral environment
uses: ./
with:
action: delete
manifest-path: test/molnett.yaml
- name: Cleanup
run: rm -r ~/.config/molnett
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @bittermandel @tmlye @mikn
71 changes: 71 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'Molnett - Ephemeral Environments'
description: 'Deploy or delete an ephemeral environment'
branding:
icon: 'download-cloud'
color: 'orange'
inputs:
action:
description: 'Either "deploy" or "delete"'
required: true
manifest-path:
description: 'Path to molnett manifest'
required: true
outputs:
environment-name:
description: 'Name of the created environment'
value: ${{ steps.env-name.outputs.env }}
service-name:
description: 'Name of the deployed service'
value: ${{ steps.deploy.outputs.name }}
runs:
using: 'composite'
steps:
- name: Check Event
if: ${{ github.event_name != 'pull_request' }}
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
run: |
echo "::error title=⛔ error hint::action needs pull request event, was $EVENT_NAME"
exit 1
- name: Check Action
if: ${{ inputs.action != 'deploy' && inputs.action != 'delete' }}
shell: bash
run: |
echo "::error title=⛔ error hint::action needs to be deploy or delete"
exit 1
- name: Check Runner OS
if: ${{ runner.os != 'Linux' }}
shell: bash
run: |
echo "::error title=⛔ error hint::Support Linux Only"
exit 1
- name: Environment Name
id: env-name
shell: bash
env:
ENV_NAME: pr-${{ github.event.number }}-${{ github.head_ref }}
run: |
# Replace special characters in branch name with dash
ENV_NAME=`echo $ENV_NAME | tr $'!\'#$%&()+,-./;<=>@]_\`{|}' '-'`
echo "env=$ENV_NAME" >> $GITHUB_OUTPUT
- name: Deploy Ephemeral Environment
id: deploy
if: ${{ inputs.action == 'deploy' }}
shell: bash
env:
ENV_NAME: ${{ steps.env-name.outputs.env }}
MANIFEST: ${{ inputs.manifest-path }}
run: |
sed -i "s/environment:.*/environment: $ENV_NAME/" $MANIFEST
molnctl environments create $ENV_NAME || true
molnctl services deploy --no-confirm $MANIFEST
FINAL_NAME=$(sed -n 's/name: //p' $MANIFEST | awk '{$1=$1};1')
echo "name=$FINAL_NAME" >> $GITHUB_OUTPUT
- name: Delete Ephemeral Environment
if: ${{ inputs.action == 'delete' }}
shell: bash
env:
ENV_NAME: ${{ steps.env-name.outputs.env }}
run: |
molnctl environments delete --no-confirm $ENV_NAME
5 changes: 5 additions & 0 deletions test/molnett.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
environment: ephemeral-test
service:
name: ephemeral-test
image: nginx
container_port: 8080