add cicd on gitea
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user