This commit is contained in:
commit
bb7d318884
6 changed files with 196 additions and 0 deletions
83
.forgejo/workflows/deploy.yml
Normal file
83
.forgejo/workflows/deploy.yml
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
# FnKit Deploy — Forgejo Actions
|
||||||
|
# Builds and deploys this function container on every push to main
|
||||||
|
# Requires: Forgejo runner with Docker socket access (fnkit deploy runner)
|
||||||
|
#
|
||||||
|
# Pipeline: git push → build image → deploy container → health check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build image
|
||||||
|
run: |
|
||||||
|
FUNCTION_NAME="fn-java"
|
||||||
|
IMAGE_NAME="fnkit-fn-${FUNCTION_NAME}:latest"
|
||||||
|
IMAGE_PREV="fnkit-fn-${FUNCTION_NAME}:prev"
|
||||||
|
|
||||||
|
echo "🔨 Building ${FUNCTION_NAME}..."
|
||||||
|
docker build -t $IMAGE_NAME .
|
||||||
|
|
||||||
|
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
|
||||||
|
echo "IMAGE_PREV=$IMAGE_PREV" >> $GITHUB_ENV
|
||||||
|
echo "FUNCTION_NAME=$FUNCTION_NAME" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Deploy container
|
||||||
|
run: |
|
||||||
|
echo "🌐 Ensuring fnkit-network exists..."
|
||||||
|
docker network create fnkit-network 2>/dev/null || true
|
||||||
|
|
||||||
|
# Tag current image as :prev for rollback
|
||||||
|
docker tag $IMAGE_NAME $IMAGE_PREV 2>/dev/null || true
|
||||||
|
|
||||||
|
echo "♻️ Replacing running container..."
|
||||||
|
docker stop $FUNCTION_NAME 2>/dev/null || true
|
||||||
|
docker rm $FUNCTION_NAME 2>/dev/null || true
|
||||||
|
|
||||||
|
echo "🚀 Starting ${FUNCTION_NAME}..."
|
||||||
|
docker run -d \
|
||||||
|
--name $FUNCTION_NAME \
|
||||||
|
--network fnkit-network \
|
||||||
|
--label fnkit.fn=true \
|
||||||
|
--label fnkit.deployed="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||||
|
--restart unless-stopped \
|
||||||
|
$IMAGE_NAME
|
||||||
|
|
||||||
|
- name: Health check
|
||||||
|
run: |
|
||||||
|
echo "🏥 Checking container health..."
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
if docker ps --filter "name=$FUNCTION_NAME" --filter "status=running" -q | grep -q .; then
|
||||||
|
echo "✅ ${FUNCTION_NAME} is running"
|
||||||
|
echo "🌐 Available at gateway: /${FUNCTION_NAME}"
|
||||||
|
else
|
||||||
|
echo "❌ Container failed to start — rolling back..."
|
||||||
|
docker logs $FUNCTION_NAME 2>&1 || true
|
||||||
|
|
||||||
|
# Rollback to previous image if available
|
||||||
|
if docker image inspect $IMAGE_PREV >/dev/null 2>&1; then
|
||||||
|
echo "🔄 Rolling back to previous image..."
|
||||||
|
docker rm $FUNCTION_NAME 2>/dev/null || true
|
||||||
|
docker run -d \
|
||||||
|
--name $FUNCTION_NAME \
|
||||||
|
--network fnkit-network \
|
||||||
|
--label fnkit.fn=true \
|
||||||
|
--label fnkit.deployed="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||||
|
--label fnkit.rollback=true \
|
||||||
|
--restart unless-stopped \
|
||||||
|
$IMAGE_PREV
|
||||||
|
echo "⚠️ Rolled back to previous version"
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Cleanup old images
|
||||||
|
run: |
|
||||||
|
echo "🧹 Cleaning up dangling images..."
|
||||||
|
docker image prune -f --filter "label=fnkit.fn=true" 2>/dev/null || true
|
||||||
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile.local
|
||||||
|
# Java
|
||||||
|
target/
|
||||||
|
*.class
|
||||||
|
*.jar
|
||||||
10
Dockerfile
Normal file
10
Dockerfile
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
FROM maven:3.9-eclipse-temurin-17
|
||||||
|
LABEL fnkit.fn="true"
|
||||||
|
WORKDIR /app
|
||||||
|
COPY pom.xml .
|
||||||
|
RUN mvn dependency:go-offline
|
||||||
|
COPY src ./src
|
||||||
|
RUN mvn package -DskipTests
|
||||||
|
EXPOSE 8080
|
||||||
|
CMD ["mvn", "function:run", "-Drun.port=8080"]
|
||||||
|
|
||||||
36
docker-compose.yml
Normal file
36
docker-compose.yml
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# Docker Compose for FnKit function with gateway integration
|
||||||
|
# Requires: docker network create fnkit-network
|
||||||
|
# Requires: fnkit-gateway running (fnkit gateway init && fnkit gateway build && fnkit gateway start)
|
||||||
|
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
fn-java:
|
||||||
|
build: .
|
||||||
|
container_name: fn-java
|
||||||
|
networks:
|
||||||
|
- fnkit-network
|
||||||
|
depends_on:
|
||||||
|
fnkit-gateway:
|
||||||
|
condition: service_started
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
# Uncomment to include gateway in this compose file
|
||||||
|
# fnkit-gateway:
|
||||||
|
# image: fnkit-gateway:latest
|
||||||
|
# container_name: fnkit-gateway
|
||||||
|
# ports:
|
||||||
|
# - "8080:8080"
|
||||||
|
# environment:
|
||||||
|
# - FNKIT_AUTH_TOKEN=${FNKIT_AUTH_TOKEN:-}
|
||||||
|
# networks:
|
||||||
|
# - fnkit-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
fnkit-network:
|
||||||
|
name: fnkit-network
|
||||||
|
external: true
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# docker-compose up -d
|
||||||
|
# curl -H "Authorization: Bearer <token>" http://localhost:8080/fn-java
|
||||||
38
pom.xml
Normal file
38
pom.xml
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>fn-java</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.cloud.functions</groupId>
|
||||||
|
<artifactId>functions-framework-api</artifactId>
|
||||||
|
<version>1.1.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.google.cloud.functions</groupId>
|
||||||
|
<artifactId>function-maven-plugin</artifactId>
|
||||||
|
<version>0.10.1</version>
|
||||||
|
<configuration>
|
||||||
|
<functionTarget>com.example.HelloWorld</functionTarget>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
13
src/main/java/com/example/HelloWorld.java
Normal file
13
src/main/java/com/example/HelloWorld.java
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.example;
|
||||||
|
|
||||||
|
import com.google.cloud.functions.HttpFunction;
|
||||||
|
import com.google.cloud.functions.HttpRequest;
|
||||||
|
import com.google.cloud.functions.HttpResponse;
|
||||||
|
|
||||||
|
public class HelloWorld implements HttpFunction {
|
||||||
|
@Override
|
||||||
|
public void service(HttpRequest request, HttpResponse response)
|
||||||
|
throws Exception {
|
||||||
|
response.getWriter().write("Hello, World!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue