Compare commits
26 Commits
d1b28f6486
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca5d3cc3e0 | ||
|
|
7d3c68066c | ||
|
|
7437e109fe | ||
|
|
eb1d6daf2c | ||
|
|
4f2dc5110f | ||
|
|
607074eb33 | ||
|
|
1202e3464f | ||
|
|
96a934a3de | ||
|
|
318f21c826 | ||
|
|
19a3de9eb9 | ||
|
|
1925adaf42 | ||
|
|
74d9eb6124 | ||
|
|
b6c0ada4a5 | ||
|
|
7f32130e27 | ||
|
|
f27f7b9ab5 | ||
|
|
bee0edbc52 | ||
|
|
56cd2dde79 | ||
|
|
de7fc52b67 | ||
|
|
19816cdad1 | ||
|
|
5037b3ea03 | ||
|
|
08c8783d45 | ||
|
|
c23b0f211b | ||
|
|
4921d765d5 | ||
|
|
69fd98e4fb | ||
|
|
b9522aa783 | ||
|
|
cf5676a674 |
56
.gitea/workflows/ci.yml
Normal file
56
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
name: Build and Deploy Scheduler
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: localhost:9999
|
||||||
|
IMAGE_NAME: ${{ secrets.PROJECT_NAME }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cleaning:
|
||||||
|
runs-on: host
|
||||||
|
steps:
|
||||||
|
- name: Cleanup docker
|
||||||
|
run: |
|
||||||
|
docker container prune -f
|
||||||
|
docker image prune -af
|
||||||
|
|
||||||
|
build_image:
|
||||||
|
runs-on: host
|
||||||
|
needs: cleaning
|
||||||
|
steps:
|
||||||
|
- name: Clone repo
|
||||||
|
run: |
|
||||||
|
git clone ${{ gitea.server_url }}/${{ gitea.repository }} .
|
||||||
|
git checkout ${{ gitea.ref_name }}
|
||||||
|
|
||||||
|
- name: Build image
|
||||||
|
run: |
|
||||||
|
docker build -t $REGISTRY/$IMAGE_NAME:${{ gitea.run_number }} .
|
||||||
|
|
||||||
|
- name: Push image
|
||||||
|
run: |
|
||||||
|
docker push $REGISTRY/$IMAGE_NAME:${{ gitea.run_number }}
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
runs-on: host
|
||||||
|
needs: build_image
|
||||||
|
steps:
|
||||||
|
- name: Clone repo
|
||||||
|
run: |
|
||||||
|
git clone ${{ gitea.server_url }}/${{ gitea.repository }} .
|
||||||
|
git checkout ${{ gitea.ref_name }}
|
||||||
|
|
||||||
|
- name: Prepare env for compose
|
||||||
|
run: |
|
||||||
|
echo "REGISTRY=$REGISTRY" > .env
|
||||||
|
echo "IMAGE_NAME=$IMAGE_NAME" >> .env
|
||||||
|
echo "TAG=${{ gitea.run_number }}" >> .env
|
||||||
|
cat .env
|
||||||
|
|
||||||
|
- name: Deploy stack
|
||||||
|
run: |
|
||||||
|
docker compose up -d
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
# Gunakan Node.js 22 sebagai base image
|
# Gunakan Node.js 22 sebagai base image
|
||||||
FROM node:22-alpine
|
FROM node:22-alpine
|
||||||
|
ENV TZ="Asia/Jakarta"
|
||||||
|
|
||||||
|
RUN apk add --no-cache curl
|
||||||
|
RUN apk add --no-cache grep
|
||||||
|
|
||||||
# Atur working directory
|
# Atur working directory
|
||||||
WORKDIR /app/scheduler-app
|
WORKDIR /app/scheduler-app
|
||||||
|
|||||||
14
compose.yml
14
compose.yml
@@ -1,14 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
image: 36.66.3.44:7007/$PROJECT_NAME:$CI_PIPELINE_ID
|
|
||||||
deploy:
|
|
||||||
replicas : 1
|
|
||||||
restart_policy :
|
|
||||||
condition: on-failure
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpus: "0.01"
|
|
||||||
memory: "50m"
|
|
||||||
restart: always
|
|
||||||
18
docker-compose.yaml
Normal file
18
docker-compose.yaml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: ${REGISTRY}/${IMAGE_NAME}:${TAG}
|
||||||
|
container_name: scheduler-app
|
||||||
|
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- /home/script:/home/script
|
||||||
|
|
||||||
|
mem_limit: 50m
|
||||||
|
cpus: 0.01
|
||||||
|
networks:
|
||||||
|
- scheduler-net
|
||||||
|
|
||||||
|
networks:
|
||||||
|
scheduler-net:
|
||||||
|
external: true
|
||||||
52
index.js
52
index.js
@@ -13,25 +13,9 @@ cron.schedule(
|
|||||||
"0 9 * * *",
|
"0 9 * * *",
|
||||||
async () => {
|
async () => {
|
||||||
const module = "Birthday Notification";
|
const module = "Birthday Notification";
|
||||||
try {
|
|
||||||
let res = await axios.get("http://36.66.3.44:7010/birthday-notification");
|
|
||||||
console.log(module, "success", res.data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(module, "error", error.message);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timezone: "Asia/Jakarta",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
cron.schedule(
|
|
||||||
"1 9 * * *",
|
|
||||||
async () => {
|
|
||||||
const module = "Workanniversary";
|
|
||||||
try {
|
try {
|
||||||
let res = await axios.get(
|
let res = await axios.get(
|
||||||
"http://36.66.3.44:7010/workanniversary-notification"
|
"http://email-notification:9997/birthday-notification",
|
||||||
);
|
);
|
||||||
console.log(module, "success", res.data);
|
console.log(module, "success", res.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -40,26 +24,26 @@ cron.schedule(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
timezone: "Asia/Jakarta",
|
timezone: "Asia/Jakarta",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
cron.schedule("* * * * *", async () => {
|
cron.schedule(
|
||||||
exec(
|
"1 9 * * *",
|
||||||
'bash /home/script/script.sh',
|
async () => {
|
||||||
(error, stdout, stderr) => {
|
const module = "Workanniversary";
|
||||||
if (error) {
|
try {
|
||||||
console.error(`Gagal menjalankan script: ${error.message}`);
|
let res = await axios.get(
|
||||||
return;
|
"http://email-notification:9997/workanniversary-notification",
|
||||||
|
);
|
||||||
|
console.log(module, "success", res.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(module, "error", error.message);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
if (stderr) {
|
{
|
||||||
console.error(`Stderr: ${stderr}`);
|
timezone: "Asia/Jakarta",
|
||||||
return;
|
},
|
||||||
}
|
);
|
||||||
|
|
||||||
console.log(`Output: ${stdout}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
res.json("What are you looking for?!");
|
res.json("What are you looking for?!");
|
||||||
|
|||||||
Reference in New Issue
Block a user