diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..42748d3 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,34 @@ +--- +kind: pipeline +name: continuous deployment +steps: + - name: build and push new image + image: plugins/docker + settings: + username: + from_secret: docker_reg_username + password: + from_secret: docker_reg_passwd + repo: decentral1se/kios-admin + tags: latest + + - name: deploy image + image: decentral1se/stack-ssh-deploy:latest + environment: + STACK_NAME: kios_admin_lumbung_space + SECRET_PAYLOAD_SECRET_VERSION: v1 + APP_ENTRYPOINT_VERSION: v1 + settings: + stack: kios_admin_lumbung_space + host: lumbung.space + deploy_key: + from_secret: drone_ssh_lumbung.space + depends_on: + - build and push new image + +trigger: + branch: + - main + event: + exclude: + - pull_request diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da92de7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM node:18-alpine as base + +FROM base as builder + +WORKDIR /home/node +COPY package*.json ./ + +COPY . . +RUN yarn install +RUN yarn build + +FROM base as runtime + +ENV NODE_ENV=production + +WORKDIR /home/node +COPY package*.json ./ + +RUN yarn install --production +COPY --from=builder /home/node/dist ./dist +COPY --from=builder /home/node/build ./build + +EXPOSE 3000 diff --git a/README.md b/README.md index c0daeed..3f87347 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,13 @@ # lumbung-kiosk-cms +[![Build Status](https://drone.autonomic.zone/api/badges/ruangrupa/lumbung-kios-cms/status.svg?ref=refs/heads/main)](https://drone.autonomic.zone/ruangrupa/lumbung-kios-cms) + This project was created using create-payload-app using the ts-blank template. ## How to Use `yarn dev` will start up your application and reload on any changes. -If you have docker and docker-compose installed, you can run `docker-compose up` +## Deploy + +Push commits, it will auto-deploy to [kios-admin.lumbung.space](https://kios-admin.lumbung.space). diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..217a765 --- /dev/null +++ b/compose.yml @@ -0,0 +1,66 @@ +--- +version: "3.8" + +services: + app: + image: decentral1se/kios-admin:latest + networks: + - proxy + - internal + volumes: + - app:/home/node/app + - node_modules:/home/node/app/node_modules + environment: + MONGODB_URI: mongodb://db:27017/payload + PORT: 3000 + NODE_ENV: production + PAYLOAD_SECRET_FILE: /run/secrets/payload_secret + PAYLOAD_CONFIG_PATH: /home/node/dist/payload.config.js + configs: + - source: app_entrypoint + target: /docker-entrypoint.sh + mode: 0555 + entrypoint: /docker-entrypoint.sh + command: node dist/server.js + secrets: + - payload_secret + deploy: + update_config: + failure_action: rollback + order: start-first + labels: + - "traefik.enable=true" + - "traefik.http.routers.kios-admin.rule=Host(`kios-admin.lumbung.space`, `www.kios-admin.lumbung.space`)" + - "traefik.http.routers.kios-admin.entrypoints=web-secure" + - "traefik.http.services.kios-admin.loadbalancer.server.port=3000" + - "traefik.http.routers.kios-admin.tls.certresolver=production" + + db: + image: mongo:6.0.3 + networks: + - internal + command: + - "--storageEngine=wiredTiger" + volumes: + - data:/data/db + +volumes: + app: + node_modules: + data: + +networks: + internal: + proxy: + external: true + +secrets: + payload_secret: + external: true + name: ${STACK_NAME}_payload_secret_${SECRET_PAYLOAD_SECRET_VERSION} + +configs: + app_entrypoint: + name: ${STACK_NAME}_app_entrypoint_${APP_ENTRYPOINT_VERSION} + file: entrypoint.sh.tmpl + template_driver: golang diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 1a2d20e..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: '3' - -services: - - payload: - image: node:18-alpine - ports: - - "3000:3000" - volumes: - - .:/home/node/app - - node_modules:/home/node/app/node_modules - working_dir: /home/node/app/ - command: sh -c "yarn install && yarn dev" - depends_on: - - mongo - environment: - MONGODB_URI: mongodb://mongo:27017/payload - PORT: 3000 - NODE_ENV: development - PAYLOAD_SECRET: TESTING - - mongo: - image: mongo:latest - ports: - - "27017:27017" - command: - - --storageEngine=wiredTiger - volumes: - - data:/data/db - logging: - driver: none - -volumes: - data: - node_modules: diff --git a/entrypoint.sh.tmpl b/entrypoint.sh.tmpl new file mode 100644 index 0000000..cb4aadd --- /dev/null +++ b/entrypoint.sh.tmpl @@ -0,0 +1,5 @@ +#!/bin/sh + +export PAYLOAD_SECRET=$(cat /run/secrets/payload_secret) + +node dist/server.js