diff --git a/.dockerignore b/.dockerignore index 6c3840719..941905c66 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,3 +5,5 @@ /docs /npm-debug.log node_modules + +src/**/*.ts \ No newline at end of file diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 000000000..392046d2c --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,25 @@ +name: Dev +on: + push: +jobs: + build_docker: + name: Build Docker image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up node & dependencies + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "npm" + - run: npm ci + - name: Run the TypeScript build + run: npx tsc + - name: Create server-package.json + run: cat package.json | grep -v electron > server-package.json + - uses: docker/setup-buildx-action@v3 + - uses: docker/build-push-action@v6 + with: + context: . + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..747432396 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,56 @@ +name: Main +on: + push: + branches: + - 'develop' +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} +jobs: + build_docker: + name: Build Docker image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Set up node & dependencies + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "npm" + - run: npm ci + - name: Run the TypeScript build + run: npx tsc + - name: Create server-package.json + run: cat package.json | grep -v electron > server-package.json + - uses: docker/setup-buildx-action@v3 + - uses: docker/build-push-action@v6 + id: push + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows_old/codeql-analysis.yml similarity index 100% rename from .github/workflows/codeql-analysis.yml rename to .github/workflows_old/codeql-analysis.yml diff --git a/.github/workflows/docker.yaml b/.github/workflows_old/docker.yaml similarity index 100% rename from .github/workflows/docker.yaml rename to .github/workflows_old/docker.yaml diff --git a/.gitignore b/.gitignore index 0e095b075..2a427512e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store node_modules/ dist/ +build/ src/public/app-dist/ npm-debug.log yarn-error.log diff --git a/Dockerfile b/Dockerfile index d8cb9b0c3..dfeb4a0d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,18 @@ # !!! Don't try to build this Dockerfile directly, run it through bin/build-docker.sh script !!! FROM node:18.18.2-alpine +# Configure system dependencies +RUN apk add --no-cache --virtual .build-dependencies \ + autoconf \ + automake \ + g++ \ + gcc \ + libtool \ + make \ + nasm \ + libpng-dev \ + python3 + # Create app directory WORKDIR /usr/src/app @@ -9,18 +21,13 @@ COPY . . COPY server-package.json package.json +# Copy TypeScript build artifacts into the original directory structure. +RUN ls +RUN cp -R build/src/* src/. +RUN rm -r build + # Install app dependencies RUN set -x \ - && apk add --no-cache --virtual .build-dependencies \ - autoconf \ - automake \ - g++ \ - gcc \ - libtool \ - make \ - nasm \ - libpng-dev \ - python3 \ && npm install \ && apk del .build-dependencies \ && npm run webpack \ diff --git a/bin/build-docker.sh b/bin/build-docker.sh index c77850eba..2b3794677 100755 --- a/bin/build-docker.sh +++ b/bin/build-docker.sh @@ -5,6 +5,9 @@ SERIES=${VERSION:0:4}-latest cat package.json | grep -v electron > server-package.json +echo "Compiling typescript..." +npx tsc + sudo docker build -t zadam/trilium:$VERSION --network host -t zadam/trilium:$SERIES . if [[ $VERSION != *"beta"* ]]; then diff --git a/package.json b/package.json index 9e6506d8a..e37e6204c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "start-test-server": "npm run qswitch-server; rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 ts-node src/www.ts", "switch-server": "rm -rf ./node_modules/better-sqlite3 && npm install", "switch-electron": "./node_modules/.bin/electron-rebuild", - "rebuild": "electron-rebuild", "qswitch-server": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-server-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node", "qswitch-electron": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-desktop-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node", "build-backend-docs": "rm -rf ./docs/backend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/becca/entities/*.js src/services/backend_script_api.js src/services/sql.js", @@ -32,7 +31,7 @@ "test-jasmine": "TRILIUM_DATA_DIR=~/trilium/data-test jasmine", "test-es6": "node -r esm spec-es6/attribute_parser.spec.js ", "test": "npm run test-jasmine && npm run test-es6", - "postinstall": "rimraf ./node_modules/canvas && npm run rebuild" + "postinstall": "rimraf ./node_modules/canvas" }, "dependencies": { "@braintree/sanitize-url": "6.0.4", diff --git a/tsconfig.json b/tsconfig.json index bf97f7be2..f0f1a3fc2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "moduleResolution": "Node", "declaration": false, "sourceMap": true, - "outDir": "./dist", + "outDir": "./build", "strict": true, "noImplicitAny": true, "resolveJsonModule": true, diff --git a/webpack.config.js b/webpack.config.js index 2e3bd7b17..41077c00e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,7 +4,7 @@ const assetPath = require('./src/services/asset_path'); module.exports = { mode: 'production', entry: { - setup: './src/public/app/setup.ts', + setup: './src/public/app/setup.js', mobile: './src/public/app/mobile.js', desktop: './src/public/app/desktop.js', },