Skip to content

Commit

Permalink
Merge pull request #40 from kcl-lang/chore-bump-kcl-lib-version-0.10.…
Browse files Browse the repository at this point in the history
…0-beta.1

chore: bump kcl lib version to 0.10.0-beta.2 and update release CI and dockerfile
  • Loading branch information
Peefy authored Aug 23, 2024
2 parents 3db7797 + 033cab8 commit d9dfccd
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 17 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
container:
image: plutolang/pluto
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update
apt install lsof
npm install
python3 -m pip install -r requirements.txt
python3 -m pip install pytest
- name: Build web
run: cd web && npm install && npm run build
- name: Test
run: ./scripts/test.sh
42 changes: 42 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.11.2
install: true

# <--- Login, build and push image to Docker Hub --->
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: kcllang/pluto-kcl-playground
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ zz_*
node_modules

# pluto
.pluto/**/*
.pluto/**/*
__pycache__
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM plutolang/pluto
WORKDIR /
COPY . .
# Install Pluto and dev dependencies
RUN npm install
# Build frontend web application
RUN cd web && npm install && npm run build
# Install backend dependencies
RUN python3 -m pip install -U -r ./requirements.txt
# Run
CMD ["pluto", "run"]
EXPOSE 8080
EXPOSE 8000
EXPOSE 8001
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Quick Start

```shell
python -m pip install -r requirements
python3 -m pip install -U -r ./requirements.txt
npm install
npm install -g pluto
make
Expand Down
15 changes: 12 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import json
import re
import tempfile
from pluto_client import Website, Router, HttpRequest, HttpResponse
from pluto_client import (
Website,
WebsiteOptions,
Router,
RouterOptions,
HttpRequest,
HttpResponse,
)
import kcl_lib.api as kcl_api

color_pattern = re.compile(r"\x1b\[[0-9;]+m")
api = kcl_api.API()
router = Router("router")
website = Website("./web/dist", "kcl-playground")
router = Router("router", RouterOptions(sim_host="0.0.0.0", sim_port="8000"))
website = Website(
"./web/dist", "kcl-playground", WebsiteOptions(sim_host="0.0.0.0", sim_port="8001")
)
website.addEnv("BACKEND_URL", router.url())


Expand Down
10 changes: 10 additions & 0 deletions app/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import requests
from main import website, router


def test_website():
assert "8000" in website.url()


def test_router():
assert "8001" in router.url()
11 changes: 4 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kcl-playground",
"version": "0.9.0",
"name": "pluto-kcl-playground",
"version": "0.10.0",
"scripts": {
"dev": "pluto run",
"test:dev": "pluto test --sim",
Expand Down
5 changes: 4 additions & 1 deletion pluto.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
configs: {}
current: aws
language: python
stacks:
- configs: {}
name: aws
platformType: AWS
provisionType: Pulumi

configs:
simulator:
address: "0.0.0.0:8080"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pluto_client
kcl_lib==0.9.0
kcl_lib==0.10.0b2
requests
57 changes: 57 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Start pluto locally
TMP_OUTPUT_FILE=/tmp/pluto_output.log
pluto run >$TMP_OUTPUT_FILE 2>&1 &
PID1=$!

# Wait for Pluto to start the project completely
while :; do
if grep -q "Successfully applied!" $TMP_OUTPUT_FILE; then
echo "The project has been successfully started."
break
else
echo "Waiting for Pluto to start the project..."
sleep 1
fi
done

# Get the project name from package.json
PROJECT_NAME=$(grep '"name":' package.json | awk -F '"' '{print $4}')
echo "Project name: $PROJECT_NAME"

# Set environment variables
PORT=8080
export PLUTO_PROJECT_NAME=$PROJECT_NAME
export PLUTO_STACK_NAME=local_run
export PLUTO_PLATFORM_TYPE=Simulator
export PLUTO_SIMULATOR_URL=http://localhost:$PORT

# Run tests
print_separator() {
local message=$1
local message_len=${#message}

local width=$(tput cols)
local separator=$(printf '=%.0s' $(seq 1 $(((width - message_len - 4) / 2))))
local bold=$(tput bold)

printf "\033[34m${bold}${separator}= %s =${separator}\033[0m\n" "$message"
}

# Output Pluto logs, which might contain useful information
tail -f $TMP_OUTPUT_FILE -n 0 &
PID2=$!

# Execute tests in the app directory
print_separator "Executing test files in the app directory"
python3 -m pytest -s -q --no-header app

# Execute tests within the app/main.py file
print_separator "Executing tests within the app/main.py file"
python3 -m pytest -s -q --no-header app/main.py

# Cleanup
kill $PID1
wait $PID1
kill $PID2
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"scripts": {
"start": "webpack serve",
"build": "env NODE_ENV=production webpack-cli",
"build": "webpack-cli",
"format": "prettier src/**/*.js src/**/*.css *.config.js --write",
"deploy": "gh-pages -d dist",
"predeploy": "yarn build"
Expand Down

0 comments on commit d9dfccd

Please sign in to comment.