diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6b1f2b5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +dist +auth +.git +.gitignore +.gitea +.github +*.md diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/ci-cd.yaml new file mode 100644 index 0000000..8fc80f9 --- /dev/null +++ b/.gitea/workflows/ci-cd.yaml @@ -0,0 +1,74 @@ +name: CI / CD + +on: + push: + branches: + - main + tags: + - 'v*' + pull_request: + branches: + - main + +permissions: + contents: read + packages: write + +jobs: + ci: + name: Lint & Build (CI) + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Type-check and compile + run: npm run build + + cd: + name: Build & Push Docker Image (CD) + needs: [ci] + if: github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: git.hrkm.my.id + username: ${{ github.actor }} + password: ${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + git.hrkm.my.id/hira/wauto + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=tag + type=sha,format=short + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b633a00 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Build TypeScript source code +FROM node:22-bookworm-slim AS builder + +WORKDIR /app + +# Install dependencies +COPY package*.json ./ +RUN npm ci + +# Copy TypeScript configuration and source +COPY tsconfig.json ./ +COPY index.ts ./ + +# Compile to JavaScript (dist/) +RUN npm run build + +# Stage 2: Production runtime image +FROM node:22-bookworm-slim AS runner + +WORKDIR /app + +ENV NODE_ENV=production + +# Install only production dependencies +COPY package*.json ./ +RUN npm ci --omit=dev && npm cache clean --force + +# Copy compiled code from builder +COPY --from=builder /app/dist ./dist + +# Create auth folder for persistent WhatsApp credentials +RUN mkdir -p /app/auth + +VOLUME ["/app/auth"] + +CMD ["npm", "start"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..8e51808 --- /dev/null +++ b/README.md @@ -0,0 +1,77 @@ +# wauto 🤖 + +A WhatsApp bot built with TypeScript, [Baileys](https://github.com/WhiskeySockets/Baileys), and [Sharp](https://sharp.pixelplumbing.com/). + +## Features +- `!ping` - Responds with pong +- `!time` - Current time in WIB (Asia/Jakarta) +- `!echo ` - Echoes your message +- `!sticker` / `!stiker` / `!s` - Converts sent or quoted image/video/sticker into a WhatsApp sticker +- `!help` - Displays command list + +--- + +## Local Development + +1. Install dependencies: + ```bash + npm install + ``` + +2. Run in development mode (with auto-reload): + ```bash + npm run dev + ``` + +3. Build and run production build: + ```bash + npm run build + npm start + ``` + +--- + +## CI / CD with Gitea Actions + +The repository includes automated CI/CD configured in [`.gitea/workflows/ci-cd.yaml`](.gitea/workflows/ci-cd.yaml): + +1. **CI (Continuous Integration)**: + - Triggers on every `push` and `pull_request` targeting `main`. + - Runs `npm ci` and `npm run build` (TypeScript compilation & type checking). + +2. **CD (Continuous Delivery)**: + - Triggers on `push` to `main` and version tags (`v*`). + - Builds a production-ready, multi-stage Docker container. + - Pushes the image to the Gitea Container Registry: + ``` + git.hrkm.my.id/hira/wauto:latest + ``` + +### Authentication for Gitea Actions Runner +The workflow uses `${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN }}`. +- If your Gitea instance has Actions package permissions enabled, `${{ secrets.GITHUB_TOKEN }}` works automatically. +- Alternatively, you can add a repository secret named `GITEA_TOKEN` with a Personal Access Token (`read:package`, `write:package`). + +--- + +## Deployment with Docker Compose + +Deploy the bot on your server using the included [`docker-compose.yml`](docker-compose.yml): + +1. Log in to Gitea Container Registry on your server: + ```bash + docker login git.hrkm.my.id + ``` + +2. Pull and start the container: + ```bash + docker compose pull + docker compose up -d + ``` + +3. Scan the WhatsApp QR code to link your account: + ```bash + docker compose logs -f + ``` + +> **Important**: The `./auth` directory is mounted into `/app/auth` inside the container so your session login credentials persist across container restarts and updates. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fb269d6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +services: + wauto: + image: git.hrkm.my.id/hira/wauto:latest + container_name: wauto + restart: unless-stopped + volumes: + # Persistent storage for WhatsApp session credentials + - ./auth:/app/auth diff --git a/package.json b/package.json index 4041110..c52e747 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "dist/index.js", "scripts": { "build": "tsc", + "typecheck": "tsc --noEmit", "start": "node dist/index.js", "dev": "tsx index.ts" },