add cicd on gitea #1
87
.gitea/workflows/cicd.yml
Normal file
87
.gitea/workflows/cicd.yml
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
name: Build, Push, and Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- production
|
||||||
|
- staging
|
||||||
|
- development
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: k8s-runner-02
|
||||||
|
env:
|
||||||
|
REGISTRY: registry.staging
|
||||||
|
IMAGE_NAME: ${{ gitea.repository }}
|
||||||
|
IMAGE_TAG: ${{ gitea.sha }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: 'Create buildkitd.toml'
|
||||||
|
run: |
|
||||||
|
cat <<EOF > buildkitd.toml
|
||||||
|
[registry."registry.staging"]
|
||||||
|
http = true
|
||||||
|
insecure = true
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: 'Set up Buildx builder'
|
||||||
|
run: |
|
||||||
|
BUILDER_NAME="builder-$(date +%s)"
|
||||||
|
echo "BUILDER_NAME=$BUILDER_NAME" >> $GITEA_ENV
|
||||||
|
|
||||||
|
docker buildx create \
|
||||||
|
--use \
|
||||||
|
--name $BUILDER_NAME \
|
||||||
|
--driver docker-container \
|
||||||
|
--config buildkitd.toml
|
||||||
|
|
||||||
|
- name: 'Build & Push Docker'
|
||||||
|
run: |
|
||||||
|
docker buildx build \
|
||||||
|
--builder $BUILDER_NAME \
|
||||||
|
-t $REGISTRY/$IMAGE_NAME:$IMAGE_TAG \
|
||||||
|
--push .
|
||||||
|
|
||||||
|
- name: 'Cleanup builder'
|
||||||
|
if: always()
|
||||||
|
run: docker buildx rm $BUILDER_NAME || true
|
||||||
|
|
||||||
|
- name: Set image name
|
||||||
|
id: export
|
||||||
|
run: |
|
||||||
|
echo "image=registry.bigdata.pens.ac.id/$IMAGE_NAME:$IMAGE_TAG" >> $GITEA_OUTPUT
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
image: ${{ steps.export.outputs.image }}
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
runs-on: k8s-runner-02
|
||||||
|
needs: build
|
||||||
|
env:
|
||||||
|
APP_NAME: ${{ gitea.repository }}
|
||||||
|
DIGEST_IMAGE: ${{ needs.build.outputs.image }}
|
||||||
|
BRANCH: ${{ gitea.ref_name }}
|
||||||
|
steps:
|
||||||
|
- name: 'Checkout repository'
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: 'Set name, image and environment'
|
||||||
|
run: |
|
||||||
|
NAME=$(echo "$APP_NAME" | sed 's/\//-/g')
|
||||||
|
sed -i "s|IMAGE_NAME|$DIGEST_IMAGE|g" k8s/deployment.yml
|
||||||
|
sed -i "s|APP_NAME|$NAME|g" k8s/deployment.yml
|
||||||
|
sed -i "s|ENVIRONMENT|$BRANCH|g" k8s/deployment.yml
|
||||||
|
|
||||||
|
sed -i "s|APP_NAME|$NAME|g" k8s/service.yml
|
||||||
|
sed -i "s|ENVIRONMENT|$BRANCH|g" k8s/service.yml
|
||||||
|
|
||||||
|
- name: 'Set kubeconfig'
|
||||||
|
run: |
|
||||||
|
mkdir -p /root/.kube
|
||||||
|
echo "${{ vars.KUBECONFIG_PA_DEVOPS }}" > /root/.kube/config
|
||||||
|
|
||||||
|
- name: 'Deploy to Cluster'
|
||||||
|
run: |
|
||||||
|
kubectl apply -f k8s
|
||||||
40
.gitea/workflows/merge.yml
Normal file
40
.gitea/workflows/merge.yml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
name: Auto Merge Downstream Branches
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- production
|
||||||
|
- staging
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
auto-merge:
|
||||||
|
runs-on: k8s-runner-02
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Required for merging branches
|
||||||
|
|
||||||
|
- name: Set up Git user
|
||||||
|
run: |
|
||||||
|
git config user.name "Gitea Auto Merge Bot"
|
||||||
|
git config user.email "actions@local.gitea"
|
||||||
|
|
||||||
|
# 🔹 If push to production, merge to staging
|
||||||
|
- name: Merge production → staging
|
||||||
|
if: gitea.ref == 'refs/heads/production'
|
||||||
|
run: |
|
||||||
|
git fetch origin staging
|
||||||
|
git checkout staging
|
||||||
|
git merge origin/production --no-edit || true
|
||||||
|
git push origin staging
|
||||||
|
|
||||||
|
# 🔹 If push to staging, merge to development
|
||||||
|
- name: Merge staging → development
|
||||||
|
if: gitea.ref == 'refs/heads/staging'
|
||||||
|
run: |
|
||||||
|
git fetch origin development
|
||||||
|
git checkout development
|
||||||
|
git merge origin/staging --no-edit || true
|
||||||
|
git push origin development
|
||||||
34
Dockerfile
Normal file
34
Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# ---- Stage 1: Build ----
|
||||||
|
FROM node:24-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install dependencies first (for caching)
|
||||||
|
COPY package.json package-lock.json* pnpm-lock.yaml* bun.lockb* ./
|
||||||
|
# If you're using pnpm or bun, adjust the install command below
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Copy the source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the SvelteKit app
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# ---- Stage 2: Production Runtime ----
|
||||||
|
FROM node:24-alpine AS runtime
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy built output and production deps
|
||||||
|
COPY --from=builder /app/package.json ./
|
||||||
|
COPY --from=builder /app/build ./build
|
||||||
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Default environment variables
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV PORT=3000
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Start the SvelteKit app
|
||||||
|
CMD ["node", "build"]
|
||||||
28
k8s/deployment.yml
Normal file
28
k8s/deployment.yml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: APP_NAME
|
||||||
|
namespace: ENVIRONMENT
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: APP_NAME
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: APP_NAME
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: APP_NAME
|
||||||
|
image: IMAGE_NAME
|
||||||
|
ports:
|
||||||
|
- containerPort: 3000
|
||||||
|
protocol: TCP
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 500m
|
||||||
|
memory: 256Mi
|
||||||
|
requests:
|
||||||
|
cpu: 250m
|
||||||
|
memory: 128Mi
|
||||||
12
k8s/service.yml
Normal file
12
k8s/service.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: APP_NAME
|
||||||
|
namespace: ENVIRONMENT
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: APP_NAME
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 3000
|
||||||
2798
package-lock.json
generated
Normal file
2798
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -35,5 +35,8 @@
|
|||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"typescript-eslint": "^8.46.1",
|
"typescript-eslint": "^8.46.1",
|
||||||
"vite": "^7.1.10"
|
"vite": "^7.1.10"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@sveltejs/adapter-node": "^5.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import adapter from '@sveltejs/adapter-auto';
|
import adapter from '@sveltejs/adapter-node';
|
||||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
|
|||||||
Reference in New Issue
Block a user