Skip to content

Commit

Permalink
👷 Switch to using SSR
Browse files Browse the repository at this point in the history
Why:
- Continuing the migration from SPA to SSR.
- The SSR site is now feature complete with the SPA site, so we can
  remove the SPA site and switch to using SSR.
- Changed the test and build to happen outside the docker build to
  simplify the docker build and to make CI faster.
  • Loading branch information
luontola committed Jul 12, 2024
1 parent 036f13c commit 0b832f7
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 282 deletions.
14 changes: 3 additions & 11 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/target/
/node_modules/
/.lein-*
/.nrepl-port
/profiles.clj
.DS_Store
*.tmp
*.bak
*.log
*.qgs~
/.git/
*
!/target/uberjar/territory-bro.jar
!/target/uberjar/classes.list
69 changes: 10 additions & 59 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Territory Bro CI

agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
type: e2-standard-2
os_image: ubuntu2204

blocks:
- name: Build
Expand All @@ -17,71 +17,22 @@ blocks:
- checkout

jobs:
- name: Test API
- name: Build
commands:
- cache restore
- cache restore m2-$SEMAPHORE_GIT_BRANCH-revision-$(checksum project.clj)
- cache restore lein-$SEMAPHORE_GIT_BRANCH-revision-$(checksum project.clj)
- sem-version java 17
- nvm install 21
- sudo apt-get install -y zopfli brotli

- npm install
- npm run build
- docker-compose up -d db
- lein test
- ./scripts/build.sh
- docker compose build --pull app

- echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- docker tag luontola/territory-bro luontola/territory-bro:ci
- docker push luontola/territory-bro:ci

- cache store
- cache store m2-$SEMAPHORE_GIT_BRANCH-revision-$(checksum project.clj) ~/.m2
- cache store lein-$SEMAPHORE_GIT_BRANCH-revision-$(checksum project.clj) ~/.lein/self-installs

- name: Test Web
commands:
- cache restore
- nvm install 21

- npm install
- npm run test

- cache store

- name: Build API
commands:
- echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- docker pull luontola/territory-bro-api:ci-builder || true
- docker pull luontola/territory-bro-api:ci || true

- docker build --pull --progress=plain
--tag luontola/territory-bro-api:ci-builder
--cache-from luontola/territory-bro-api:ci-builder
--file Dockerfile-api --target builder .

- docker build --pull --progress=plain
--tag luontola/territory-bro-api:ci
--cache-from luontola/territory-bro-api:ci
--cache-from luontola/territory-bro-api:ci-builder
--file Dockerfile-api .

- docker push luontola/territory-bro-api:ci-builder
- docker push luontola/territory-bro-api:ci

- name: Build Web
commands:
- echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- docker pull luontola/territory-bro-web:ci-builder || true
- docker pull luontola/territory-bro-web:ci || true

- docker build --pull --progress=plain
--tag luontola/territory-bro-web:ci-builder
--cache-from luontola/territory-bro-web:ci-builder
--build-arg VITE_GIT_COMMIT=$(git rev-parse --short HEAD)
--file Dockerfile-web --target builder .

- docker build --pull --progress=plain
--tag luontola/territory-bro-web:ci
--cache-from luontola/territory-bro-web:ci
--cache-from luontola/territory-bro-web:ci-builder
--build-arg VITE_GIT_COMMIT=$(git rev-parse --short HEAD)
--file Dockerfile-web .

- docker push luontola/territory-bro-web:ci-builder
- docker push luontola/territory-bro-web:ci
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM eclipse-temurin:17-jre-focal

EXPOSE 8080
ENV PORT=8080 \
DATABASE_URL="jdbc:postgresql://localhost/territorybro?user=territorybro&password=territorybro"

# the user should have no write permissions, even to its home
RUN adduser --no-create-home --home /app app && \
mkdir /app
WORKDIR /app

COPY target/uberjar/territory-bro.jar /app/

# prepare AppCDS shared archive
COPY target/uberjar/classes.list /app/
RUN java -Xshare:dump \
-XX:SharedClassListFile=classes.list \
-XX:SharedArchiveFile=classes.jsa \
--class-path territory-bro.jar && \
rm classes.list

USER app
ENTRYPOINT ["java", "-Xshare:on", "-XX:SharedArchiveFile=classes.jsa", "-jar", "territory-bro.jar"]
88 changes: 0 additions & 88 deletions Dockerfile-api

This file was deleted.

39 changes: 0 additions & 39 deletions Dockerfile-web

This file was deleted.

2 changes: 1 addition & 1 deletion dev-config.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:dev true
:port 8081
:port 8080
:database-url "jdbc:postgresql://localhost/territorybro?user=territorybro&password=territorybro"
:gis-database-host "localhost"
:auth0-domain "luontola.eu.auth0.com"
Expand Down
21 changes: 4 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
version: '2'
services:

web:
app:
build:
context: .
dockerfile: Dockerfile-web
image: luontola/territory-bro-web
environment:
API_URL: http://api:8080
mem_reservation: 10m
mem_limit: 20m
ports:
- "127.0.0.1:8080:80"

api:
build:
context: .
dockerfile: Dockerfile-api
image: luontola/territory-bro-api
dockerfile: Dockerfile
image: luontola/territory-bro
environment:
PUBLIC_URL: http://localhost:8080
AUTH0_DOMAIN: luontola.eu.auth0.com
Expand All @@ -30,7 +17,7 @@ services:
mem_reservation: 300m
mem_limit: 500m
ports:
- "127.0.0.1:8081:8080"
- "127.0.0.1:8080:8080"
- "127.0.0.1:7000:7000"

db:
Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
:test-selectors {:default (fn [m] (not (:e2e m)))
:e2e :e2e}

:profiles {:uberjar {:omit-source true
:profiles {:uberjar {:auto-clean false
:omit-source true
:aot :all
:uberjar-name "territory-bro.jar"}

Expand Down
20 changes: 18 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@ export VITE_GIT_COMMIT=$(git rev-parse --short HEAD)
docker compose up -d db

lein clean
lein test
lein uberjar

npm install
npm run test
npm run build

# macOS find doesn't support -regextype, and GNU find doesn't support -E
if [[ "$OSTYPE" == "darwin"* ]]; then
find -E target/web-dist/public \
-type f \
-iregex '.*\.(html|js|map|css|svg|otf|ttf|txt|json)' \
-print -exec zopfli '{}' \; -exec brotli -f '{}' \;
else
find target/web-dist/public \
-type f \
-regextype posix-extended \
-iregex '.*\.(html|js|map|css|svg|otf|ttf|txt|json)' \
-print -exec zopfli '{}' \; -exec brotli -f '{}' \;
fi

lein do kaocha fast slow, uberjar

java -XX:DumpLoadedClassList=target/uberjar/classes.list -Dconf=test-config.edn -jar "target/uberjar/territory-bro.jar" app-cds-setup
17 changes: 6 additions & 11 deletions scripts/release-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ TAG="${1:-$DEFAULT_TAG}"
echo TAG="$TAG"
set -x

git tag "$TAG"
docker pull "luontola/territory-bro:ci"

docker pull "luontola/territory-bro-api:ci"
docker pull "luontola/territory-bro-web:ci"
git tag "$TAG"

docker tag "luontola/territory-bro-api:ci" "luontola/territory-bro-api:$TAG"
docker tag "luontola/territory-bro-api:ci" "luontola/territory-bro-api:latest"
docker tag "luontola/territory-bro-web:ci" "luontola/territory-bro-web:$TAG"
docker tag "luontola/territory-bro-web:ci" "luontola/territory-bro-web:latest"
docker tag "luontola/territory-bro:ci" "luontola/territory-bro:$TAG"
docker tag "luontola/territory-bro:ci" "luontola/territory-bro:latest"

docker push "luontola/territory-bro-api:$TAG"
docker push "luontola/territory-bro-api:latest"
docker push "luontola/territory-bro-web:$TAG"
docker push "luontola/territory-bro-web:latest"
docker push "luontola/territory-bro:$TAG"
docker push "luontola/territory-bro:latest"

git push origin "$TAG"
18 changes: 18 additions & 0 deletions scripts/release-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -eu
#: ${1:? Usage: $0 RELEASE_VERSION}
DEFAULT_TAG=$(date +%Y-%m-%d)
TAG="${1:-$DEFAULT_TAG}"
echo TAG="$TAG"
set -x

docker compose build --pull app

git tag "$TAG"

docker tag "luontola/territory-bro:latest" "luontola/territory-bro:$TAG"

docker push "luontola/territory-bro:$TAG"
docker push "luontola/territory-bro:latest"

git push origin "$TAG"
Loading

0 comments on commit 0b832f7

Please sign in to comment.