Skip to content

Commit

Permalink
Update the :edge images to use the very latest web UI version (actual…
Browse files Browse the repository at this point in the history
…budget#121)

- The `:edge` and `:edge-alpine` containers will now download the latest
commit of the frontend repo and build it when they are built.
- The backend dependency install process now uses the local copy of Yarn
(from actualbudget#56) to install dependencies
- Extraneous files are no longer copied into the production image. This
is mostly a win for local builds (where the `.yarn` cache folder used to
get copied in) but it’s also a small win for CI-built containers which
will no longer have the README/configuration files/Yarn source code
lying around
- The dockerfiles now say `EXPOSE 5006`. This doesn’t have an effect on
anything by default as far as I can tell but it does mean that tools
know we will be listening on that port and can help users set up their
container accordingly (for example, Docker Desktop)
- Remove some extraneous dependencies from the containers (including
openssl)

---------

Co-authored-by: Trevor Farlow <[email protected]>
  • Loading branch information
j-f1 and trevdor authored Mar 6, 2023
1 parent 19cd163 commit a52ae2d
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 57 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
node_modules
user-files
server-files

# Yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
82 changes: 82 additions & 0 deletions .github/workflows/docker-edge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build Edge Docker Image

# Edge Docker images are built for every commit, and daily
on:
push:
branches:
- master
paths-ignore:
- README.md
- LICENSE.txt
schedule:
- cron: '0 0 * * *'

env:
IMAGES: |
jlongster/actual-server
ghcr.io/actualbudget/actual-server
# Creates the following tags:
# - actual-server:edge
TAGS: |
type=edge,value=edge
jobs:
build:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# Push to both Docker Hub and Github Container Registry
images: ${{ env.IMAGES }}
tags: ${{ env.TAGS }}

- name: Docker meta for Alpine image
id: alpine-meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGES }}
flavor: suffix=-alpine
tags: $${{ env.TAGS }}

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push standard image
uses: docker/build-push-action@v4
with:
context: .
push: true
file: docker/edge-ubuntu.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}

- name: Build and push Alpine image
uses: docker/build-push-action@v4
with:
context: .
push: true
file: docker/edge-alpine.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.alpine-meta.outputs.tags }}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Build Docker Image
name: Build Stable Docker Image

# Docker Images are built for every push to master or when a new tag is created
# Stable Docker images are built for every new tag
on:
push:
branches:
- master
tags:
- 'v*.*.*'
paths-ignore:
Expand All @@ -18,12 +16,10 @@ env:
# Creates the following tags:
# - actual-server:latest (see docker/metadata-action flavor inputs, below)
# - actual-server:edge (for master)
# - actual-server:1.3
# - actual-server:1.3.7
# - actual-server:sha-90dd603
TAGS: |
type=edge,value=edge
type=semver,pattern={{version}}
type=sha
Expand All @@ -35,35 +31,34 @@ jobs:
- uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# Push to both Docker Hub and Github Container Registry
images: ${{ env.IMAGES }}
# Automatically update :latest for our semver tags
flavor: |
latest=auto
# Automatically update :latest
flavor: latest=true
tags: ${{ env.TAGS }}

- name: Docker meta for Alpine image
id: alpine-meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGES }}
# Automatically update :latest for our semver tags and suffix all tags
# Automatically update :latest
flavor: |
latest=auto
latest=true
suffix=-alpine,onlatest=true
tags: $${{ env.TAGS }}

- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -76,18 +71,19 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push standard image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
push: true
file: docker/stable-ubuntu.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}

- name: Build and push Alpine image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
push: true
file: Dockerfile.alpine
file: docker/stable-alpine.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.alpine-meta.outputs.tags }}
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'

yarnPath: .yarn/releases/yarn-3.2.1.cjs
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions Dockerfile
15 changes: 0 additions & 15 deletions Dockerfile.alpine

This file was deleted.

28 changes: 28 additions & 0 deletions docker/edge-alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM alpine:3.17 as base
RUN apk add --no-cache nodejs yarn npm python3 openssl build-base
WORKDIR /app
ADD .yarn ./.yarn
ADD yarn.lock package.json .yarnrc.yml ./
RUN yarn workspaces focus --all --production

# Since we’re just using static files, use the Ubuntu image to build the frontend
# (otherwise electron fails to build)
FROM node:16-bullseye as frontend
WORKDIR /frontend
# Rebuild whenever there are new commits to the frontend
ADD "https://api.github.com/repos/actualbudget/actual/commits" /tmp/actual-commit.json
RUN git clone --depth=1 https://github.com/actualbudget/actual /frontend
RUN yarn install
RUN ./bin/package-browser

FROM alpine:3.17 as prod
RUN apk add --no-cache nodejs tini
WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
COPY --from=frontend /frontend/packages/desktop-client/build /public
ADD package.json app.js ./
ADD src ./src
ENTRYPOINT ["/sbin/tini","-g", "--"]
ENV ACTUAL_WEB_ROOT=/public
EXPOSE 5006
CMD ["node", "app.js"]
26 changes: 26 additions & 0 deletions docker/edge-ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:16-bullseye as base
RUN apt-get update && apt-get install -y openssl
WORKDIR /app
ADD .yarn ./.yarn
ADD yarn.lock package.json .yarnrc.yml ./
RUN yarn workspaces focus --all --production

FROM node:16-bullseye as frontend
WORKDIR /frontend
# Rebuild whenever there are new commits to the frontend
ADD "https://api.github.com/repos/actualbudget/actual/commits" /tmp/actual-commit.json
RUN git clone --depth=1 https://github.com/actualbudget/actual /frontend
RUN yarn install
RUN ./bin/package-browser

FROM node:16-bullseye-slim as prod
RUN apt-get update && apt-get install tini && apt-get clean -y && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
COPY --from=frontend /frontend/packages/desktop-client/build /public
ADD package.json app.js ./
ADD src ./src
ENTRYPOINT ["/usr/bin/tini","-g", "--"]
ENV ACTUAL_WEB_ROOT=/public
EXPOSE 5006
CMD ["node", "app.js"]
16 changes: 16 additions & 0 deletions docker/stable-alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM alpine:3.17 as base
RUN apk add --no-cache nodejs yarn npm python3 openssl build-base
WORKDIR /app
ADD .yarn ./.yarn
ADD yarn.lock package.json .yarnrc.yml ./
RUN yarn workspaces focus --all --production

FROM alpine:3.17 as prod
RUN apk add --no-cache nodejs tini
WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
ADD package.json app.js ./
ADD src ./src
ENTRYPOINT ["/sbin/tini","-g", "--"]
EXPOSE 5006
CMD ["node", "app.js"]
16 changes: 16 additions & 0 deletions docker/stable-ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:16-bullseye as base
RUN apt-get update && apt-get install -y openssl
WORKDIR /app
ADD .yarn ./.yarn
ADD yarn.lock package.json .yarnrc.yml ./
RUN yarn workspaces focus --all --production

FROM node:16-bullseye-slim as prod
RUN apt-get update && apt-get install tini && apt-get clean -y && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
ADD package.json app.js ./
ADD src ./src
ENTRYPOINT ["/usr/bin/tini","-g", "--"]
EXPOSE 5006
CMD ["node", "app.js"]
7 changes: 2 additions & 5 deletions src/account-db.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import { join } from 'node:path';
import openDatabase from './db.js';
import config, { projectRoot } from './load-config.js';
import config, { sqlDir } from './load-config.js';
let accountDb = null;

export default function getAccountDb() {
Expand All @@ -17,10 +17,7 @@ export default function getAccountDb() {
accountDb = openDatabase(dbPath);

if (needsInit) {
let initSql = fs.readFileSync(
join(projectRoot, 'sql/account.sql'),
'utf8'
);
let initSql = fs.readFileSync(join(sqlDir, 'account.sql'), 'utf8');
accountDb.exec(initSql);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/load-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

export const projectRoot = path.dirname(
path.dirname(fileURLToPath(import.meta.url))
);
const projectRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
export const sqlDir = path.join(projectRoot, 'src', 'sql');
let defaultDataDir = fs.existsSync('/data') ? '/data' : projectRoot;

function parseJSON(path) {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/sync-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'node:path';
import openDatabase from './db.js';
import { getPathForGroupFile } from './util/paths.js';

import { projectRoot } from './load-config.js';
import { sqlDir } from './load-config.js';

import actual from '@actual-app/api';
let merkle = actual.internal.merkle;
Expand All @@ -17,7 +17,7 @@ function getGroupDb(groupId) {
let db = openDatabase(path);

if (needsInit) {
let sql = readFileSync(join(projectRoot, 'sql/messages.sql'), 'utf8');
let sql = readFileSync(join(sqlDir, 'messages.sql'), 'utf8');
db.exec(sql);
}

Expand Down

0 comments on commit a52ae2d

Please sign in to comment.