Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#227 build basic backend deb package #228

Merged
merged 52 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1aaed7a
#227 add script for building backend deb package
elKei24 Feb 4, 2021
a17bd83
#227 add config for circle ci to build backend
elKei24 Feb 4, 2021
72a660a
#227 pack deb in pipeline
elKei24 Feb 4, 2021
7426a89
#227 do not build again in deb script
elKei24 Feb 4, 2021
bed47c4
#227 improve circle ci config
elKei24 Feb 4, 2021
f1076df
#227 make deb script configurable using params
elKei24 Feb 4, 2021
d040302
#227 store deb as artifact for real
elKei24 Feb 4, 2021
fb6a28f
#227 add systemd service file
elKei24 Feb 4, 2021
975e62a
#227 add backend to multiuser target
elKei24 Feb 4, 2021
84afdc3
#227 deploy .deb using scp
elKei24 Feb 4, 2021
46078bc
#227 adapt deployment to server config
elKei24 Feb 4, 2021
a0a025a
#227 check host key before scp-ing
elKei24 Feb 4, 2021
1bb0d64
#227 enable deploy for main only
elKei24 Feb 4, 2021
706780b
Retry to deploy
maxammann Feb 5, 2021
89e03c8
Switch to sftp
maxammann Feb 5, 2021
4d0abec
Fix service file
maxammann Feb 5, 2021
04c6e6b
Fix path
maxammann Feb 5, 2021
4a53654
Change postgres config
maxammann Feb 5, 2021
0608384
Add unix socket support
maxammann Feb 5, 2021
543b97c
Make host configurable
maxammann Feb 5, 2021
8c5c777
Remove hold step for now
maxammann Feb 5, 2021
abc4a3c
Add comment
maxammann Feb 5, 2021
eb1ffbd
Fix urls
maxammann Feb 5, 2021
bb8166a
Add dart start scripts
maxammann Feb 5, 2021
a0cdf94
Add setting to enable production mode
maxammann Feb 5, 2021
c0396f7
Only for main
maxammann Feb 5, 2021
3c936c8
Update intellij configs
maxammann Feb 6, 2021
f2cdbe7
Update configs and docs
maxammann Feb 6, 2021
d855554
Update staging config
maxammann Feb 6, 2021
78d8b7c
Update nginx config
maxammann Feb 6, 2021
f8cc06e
Update nginx config
maxammann Feb 6, 2021
80ef3e9
use try files
maxammann Feb 6, 2021
e5bae80
Update
maxammann Feb 6, 2021
f2e8fa4
Update
maxammann Feb 6, 2021
c7e7be6
Update
maxammann Feb 6, 2021
132e2ec
Set index
maxammann Feb 6, 2021
dc61d69
Add try files
maxammann Feb 6, 2021
2db5bfd
Add try files
maxammann Feb 6, 2021
6f4e366
Fix config
maxammann Feb 6, 2021
460cceb
Do not rewrite in staging
maxammann Feb 6, 2021
c055d39
add access token
maxammann Feb 6, 2021
bf00c12
#227 pack administration backend
elKei24 Feb 6, 2021
a6810fa
#227 fix script and deploy
elKei24 Feb 6, 2021
a693479
#227 add description/depends only if set
elKei24 Feb 6, 2021
5b0917a
#227 improve sftp job output
elKei24 Feb 6, 2021
8ee65cd
#227 improve npm caching
elKei24 Feb 6, 2021
0ae5a92
#227 check also package.json when caching
elKei24 Feb 6, 2021
18b0258
#227 undo deployment from feature branch
elKei24 Feb 6, 2021
9caf839
Merge branch 'main' into 227-deb-packages
elKei24 Feb 8, 2021
2a697c9
Add static files
maxammann Feb 9, 2021
a599f1f
Set germany data source and remove unsupported fonts
maxammann Feb 10, 2021
c028d42
Use mapbox libre
maxammann Feb 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
version: 2.1
orbs:
gradle: circleci/[email protected]
workflows:
default:
jobs:
- be-build
- ad-build
- be-pack:
requires:
- be-build
- ad-pack:
requires:
- ad-build
- meta-pack
- deploy:
requires:
- be-pack
- ad-pack
- meta-pack
filters:
branches:
only:
- main

jobs:
be-build:
environment:
# Configure the JVM and Gradle to avoid OOM errors
_JAVA_OPTIONS: "-Xmx3g"
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2"
docker:
- image: circleci/openjdk:11.0.3-jdk-stretch
working_directory: ~/project/backend
steps:
- checkout:
path: ~/project
- restore_cache:
key: v2-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- restore_cache:
key: v2-gradle-cache-{{ checksum "build.gradle.kts" }}
- run: ./gradlew build
- save_cache:
paths:
- .gradle/wrapper
key: v2-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- save_cache:
paths:
- .gradle/caches
key: v2-gradle-cache-{{ checksum "build.gradle.kts" }}
- store_artifacts:
path: build/libs
- persist_to_workspace:
root: ~/project
paths:
- backend/build/distributions/*

ad-build:
docker:
- image: cimg/node:15.8.0
working_directory: ~/project/administration
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- v1-node-modules-{{ checksum "package.json" }}-{{checksum "package-lock.json" }}
- run:
name: Install node dependencies
command: "[ ! -d node_modules ] && npm ci --loglevel warn --yes || echo package.json and package-lock.json unchanged. Using cache."
- run: npm run-script build
- save_cache:
paths:
- node_modules
key: v1-node-modules-{{ checksum "package.json" }}-{{checksum "package-lock.json" }}
- store_artifacts:
path: build
- persist_to_workspace:
root: ~/project
paths:
- administration/build

be-pack:
docker:
- image: cimg/base:2020.01
working_directory: ~/project/backend
steps:
- checkout:
path: ~/project
- attach_workspace:
at: /tmp/workspace
- run: ../scripts/pack_deb.sh -v 0.1 -t /tmp/workspace/backend/build/distributions/*.tar -s ../scripts/eak-backend.service -d "Backend server for the Ehrenamtskarte app" -n "eak-backend" -c "default-jre"
- run: |
mkdir -p /tmp/artifacts/debs
cp *.deb /tmp/artifacts/debs
- store_artifacts:
path: /tmp/artifacts
- persist_to_workspace:
root: /tmp/artifacts
paths:
- debs/*.deb

ad-pack:
docker:
- image: cimg/base:2020.01
working_directory: ~/project/administration
steps:
- checkout:
path: ~/project
- attach_workspace:
at: /tmp/workspace
- run: ../scripts/pack_deb.sh -v 0.1 -f /tmp/workspace/administration/build -d "Administration backend for the Ehrenamtskarte app" -n "eak-administration"
- run: |
mkdir -p /tmp/artifacts/debs
cp *.deb /tmp/artifacts/debs
- store_artifacts:
path: /tmp/artifacts
- persist_to_workspace:
root: /tmp/artifacts
paths:
- debs/*.deb

meta-pack:
docker:
- image: cimg/base:2020.01
working_directory: ~/project/administration
steps:
- checkout:
path: ~/project
- run: ../scripts/pack_deb.sh -v 0.1 -d "Meta package for the Ehrenamtskarte app" -n "eak" -c "eak-backend, eak-administration"
- run: |
mkdir -p /tmp/artifacts/debs
cp *.deb /tmp/artifacts/debs
- store_artifacts:
path: /tmp/artifacts
- persist_to_workspace:
root: /tmp/artifacts
paths:
- debs/*.deb

deploy:
docker:
- image: cimg/base:2020.01
steps:
- attach_workspace:
at: /tmp/workspace
- add_ssh_keys:
fingerprints:
- "5c:8a:70:dc:61:9d:fa:c2:c2:6d:2d:fc:4a:ab:d2:e3"
- run:
name: "SFTP upload"
command: |
echo $APT_HOST_FINGERPRINT > known_hosts
echo "Uploading: " /tmp/workspace/debs/*.deb
sftp -b - -o UserKnownHostsFile=known_hosts [email protected]:/local-apt-repository/ \<<< "put -r /tmp/workspace/debs/*.deb"
6 changes: 1 addition & 5 deletions .idea/ehrenamtskarte.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/runConfigurations/Run_Flutter__prod__.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Run_Flutter__staging_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion administration/administration.iml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/node_modules" />
<excludeFolder url="file://$MODULE_DIR$/__generated__" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
Expand Down
2 changes: 2 additions & 0 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ dependencies {
implementation("org.jetbrains.exposed", "exposed-dao", exposed_version)
implementation("org.jetbrains.exposed", "exposed-jdbc", exposed_version)
implementation("org.postgresql", "postgresql", "42.2.18")
implementation("com.kohlschutter.junixsocket", "junixsocket-core", "2.3.2")
implementation("com.kohlschutter.junixsocket", "junixsocket-common", "2.3.2")

implementation("net.postgis", "postgis-jdbc", "2.5.0")

Expand Down
4 changes: 1 addition & 3 deletions backend/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

exposed_version=0.28.1

app.postgres.host=localhost
app.postgres.port=5432
app.postgres.url=jdbc:postgresql://localhost:5432/ehrenamtskarte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't we have some problems with that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to the previous way. I no longer concat the url in java but pass the whole one here.

app.postgres.user=postgres
app.postgres.password=postgres
app.postgres.database=ehrenamtskarte

app.import.xml=https://www.lbe.bayern.de/engagement-anerkennen/ehrenamtskarte/akzeptanzstellen/app-daten.xml
app.import.json_1=https://bayerische_eak:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Database {
}

val db by lazy {
connect("jdbc:postgresql://" +
"${System.getProperty("app.postgres.host")}:${System.getProperty("app.postgres.port")}" +
"/${System.getProperty("app.postgres.database")}", driver = "org.postgresql.Driver",
user = System.getProperty("app.postgres.user"), password = System.getProperty("app.postgres.password"))
connect(
System.getProperty("app.postgres.url"), driver = "org.postgresql.Driver",
user = System.getProperty("app.postgres.user"), password = System.getProperty("app.postgres.password")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ package app.ehrenamtskarte.backend.common.webservice
import io.javalin.Javalin
import io.javalin.http.staticfiles.Location

const val PORT = 7000
const val DEFAULT_PORT = "7000"

class WebService {
fun start() {
val production = System.getProperty("app.production", "").isNotEmpty()
val host = System.getProperty("app.host", "0.0.0.0")
val port = Integer.parseInt(System.getProperty("app.port", DEFAULT_PORT))
val app = Javalin.create { cfg ->
cfg.enableDevLogging()
cfg.enableCorsForAllOrigins()
if (!production) {
cfg.enableDevLogging()
cfg.enableCorsForAllOrigins()
}
cfg.addStaticFiles("/graphiql", "/graphiql", Location.CLASSPATH)
}.start(PORT)
}.start(host, port)

println("Server is running at http://localhost:${PORT}")
println("Goto http://localhost:${PORT}/graphiql for a graphical editor")
println("Server is running at http://${host}:${port}")
println("Goto http://${host}:${port}/graphiql for a graphical editor")

val graphQLHandler = GraphQLHandler()
app.post("/") { ctx -> graphQLHandler.handle(ctx) }
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
backend:
build: ./backend/
environment:
- BACKEND_OPTS=-Dapp.postgres.host=db-postgis -Dapp.postgres.user=postgres -Dapp.postgres.port=5432 -Dapp.postgres.password=postgres -Dapp.postgres.database=ehrenamtskarte
- BACKEND_OPTS=-Dapp.postgres.url=jdbc:postgresql://db-postgis:5432/ehrenamtskarte -Dapp.postgres.user=postgres -Dapp.postgres.password=postgres
depends_on:
- db-postgis
networks:
Expand Down
38 changes: 26 additions & 12 deletions docker/reverse_proxy/nginx-development.conf
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
# Nginx config for routing within the docker network (development)

upstream martin {
server martin:3000;
server martin:3000; # Host within docker network
}

server {
listen 80;
listen 80 default_server;
server_name localhost;

location ~ /tiles/(?<fwd_path>.*) {
root /usr/share/nginx/html;

location = /map.html {
}

location = /style.json {
add_header 'Access-Control-Allow-Origin' '*';

sub_filter_once off;
sub_filter_types application/json;
sub_filter "https://tiles.staging.ehrenamtskarte.app" "http://localhost:5002";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that right for development?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems right. It gets replaced with localhost like before.


try_files $uri /style.json;
}

location ^~ /sprites {
add_header 'Access-Control-Allow-Origin' '*';

try_files $uri $uri;
}

location ~ /(?<fwd_path>.*) {
proxy_set_header X-Rewrite-URL $request_uri;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://martin/$fwd_path$is_args$args;
}

location / {
add_header 'Access-Control-Allow-Origin' '*';
sub_filter_once off;
sub_filter_types application/json;
sub_filter "https://vector.ehrenamtskarte.app" "http://localhost:5002";
root /usr/share/nginx/html;
index index.html;
}
}

37 changes: 25 additions & 12 deletions docker/reverse_proxy/nginx-staging.conf
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
# Nginx config for routing within the docker network (staging)

upstream martin {
server martin:3000;
server martin:3000; # Host within docker network
}

upstream backend {
server backend:7000;
server backend:7000; # Host within docker network
}

server {
listen 80;
server_name vector.ehrenamtskarte.app;
listen 80 default_server;
server_name tiles.staging.ehrenamtskarte.app;

root /usr/share/nginx/html;

location = /map.html {
}

location = /style.json {
add_header 'Access-Control-Allow-Origin' '*';

try_files $uri /style.json;
}

location ^~ /sprites {
add_header 'Access-Control-Allow-Origin' '*';

try_files $uri $uri;
}

location ~ /tiles/(?<fwd_path>.*) {
location ~ /(?<fwd_path>.*) {
proxy_set_header X-Rewrite-URL $request_uri;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://martin/$fwd_path$is_args$args;
}

location / {
add_header 'Access-Control-Allow-Origin' '*';
root /usr/share/nginx/html;
index index.html;
}
}

server {
listen 80;
server_name api.ehrenamtskarte.app;
server_name api.staging.ehrenamtskarte.app;

location / {
proxy_set_header Host $http_host;
Expand Down
Loading