Skip to content

Commit

Permalink
Add config files and build scripts (#1)
Browse files Browse the repository at this point in the history
* Added config file

* Add Makefile and docker-compose.yml

* Add Dockerfile

* Remove noise from logs

* Changed jdbc driver

* Add README, make-release and build workflow. Tweaked Docker file
  • Loading branch information
matsbov committed Sep 7, 2023
1 parent 824aab4 commit c79bf52
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build

on:
push:
branches:
- '*'
tags:
- '*'

jobs:

build:

runs-on: ubuntu-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run build with Gradle Wrapper
run: ./gradlew build

- name: Upload war
uses: actions/upload-artifact@v3
with:
name: package
path: build/libs

- name: Log in to the Container registry
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}

- name: Build and push Docker image
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM tomcat:9.0-jdk11-temurin

RUN mkdir -p /data/logger/config

COPY build/libs/logger-service-*-plain.war $CATALINA_HOME/webapps/ROOT.war

ENV DOCKERIZE_VERSION v0.7.0

RUN apt-get update \
&& apt-get install -y wget \
&& wget -O - https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar xzf - -C /usr/local/bin \
&& apt-get autoremove -yqq --purge wget && rm -rf /var/lib/apt/lists/*
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
run:
docker compose up --detach mysqldb
./gradlew bootRun

# You need to change dataSource.url in logger-config.properties
# to use 'mysqldb' instead of '127.0.0.1' for this to work
run-docker:
./gradlew build
docker compose build --no-cache
docker compose up --detach

release:
@./sbdi/make-release.sh
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:

mysqldb:
image: mysql:5.7
volumes:
- db_data_logger:/var/lib/mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: logger
MYSQL_USER: logger
MYSQL_PASSWORD: logger
ports:
- 3306:3306

logger:
depends_on:
- mysqldb
image: sbdi/logger-dev
build:
context: .
ports:
- 8080:8080
volumes:
- ./sbdi/data/config/logger-config.properties:/data/logger/config/logger-config.properties

volumes:
db_data_logger:
# db_data_logger_prod:
# driver: local
# driver_opts:
# type: none
# o: bind
# device: "/home/mats/Documents/sbdi/logger/db_data_logger"
8 changes: 8 additions & 0 deletions grails-app/conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
</encoder>
</appender>

<!-- SBDI: this is to get rid of noise in the logs -->
<logger name="org.grails.config.NavigableMap" level="ERROR">
<appender-ref ref="STDOUT" />
</logger>
<logger name="org.hibernate.orm.deprecation" level="ERROR">
<appender-ref ref="STDOUT" />
</logger>

<root level="warn">
<appender-ref ref="STDOUT" />
</root>
Expand Down
35 changes: 35 additions & 0 deletions sbdi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Logger

## Setup

### Config and data directory
Create data directory at `/data/logger` and populate as below (it is easiest to symlink the config files to the ones in this repo):
```
mats@xps-13:/data/logger$ tree
.
└── config
└── logger-config.properties -> /home/mats/src/biodiversitydata-se/logger-service/sbdi/data/config/logger-config.properties
```

### Database
An empty database will be created the first time the application starts. You can then export the database from production using `mysqldump` and import it.

## Usage
Run locally:
```
make run
```

Build and run in Docker (using Tomcat). This requires a small change in the config file to work. See comment in Makefile.
```
make run-docker
```

Make a release. This will create a new tag and push it. A new Docker container will be built on Github.
```
mats@xps-13:~/src/biodiversitydata-se/logger (master *)$ make release
Current version: 1.0.1. Enter the new version (or press Enter for 1.0.2):
Updating to version 1.0.2
Tag 1.0.2 created and pushed.
```
58 changes: 58 additions & 0 deletions sbdi/data/config/logger-config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# CAS Config
security.cas.appServerName=http://localhost:8080
security.cas.loginUrl=https://auth.biodiversitydata.se/cas/login
security.cas.logoutUrl=https://auth.biodiversitydata.se/cas/logout
gateway=false
security.cas.adminRole=ROLE_ADMIN
disableCAS=false
security.cas.casServerName=https://auth.biodiversitydata.se
security.cas.casServerUrlPrefix=https://auth.biodiversitydata.se/cas
security.cas.authCookieName=
#security.cas.authenticateOnlyIfLoggedInFilterPattern=/,/apps,/category
security.cas.bypass=false
userDetails.url = https://auth.biodiversitydata.se/userdetails/

# Legacy CAS properties
casProperties=casServerLoginUrl,serverName,centralServer,casServerName,uriFilterPattern,uriExclusionFilter,authenticateOnlyIfLoggedInFilterPattern,casServerLoginUrlPrefix,gateway,casServerUrlPrefix,contextPath
casServerName=https://auth.biodiversitydata.se
casServerUrlPrefix=https://auth.biodiversitydata.se
casServerLoginUrl=https://auth.biodiversitydata.se/login

ala.admin.systemMessage.path=/data/logger/config

# Grails config
serverURL=http://localhost:8080
grails.serverURL=http://localhost:8080
serverName=http://localhost:8080
contextPath=

# Data Source properties
dataSource.dbCreate=none
dataSource.driverClassName=com.mysql.cj.jdbc.Driver
#dataSource.dialect=org.hibernate.dialect.MySQL8Dialect
dataSource.url=jdbc\:mysql\://127.0.0.1/logger?autoReconnect=true&connectTimeout=0&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Europe/Stockholm
dataSource.username=logger
dataSource.password=logger

# Header and footer
headerAndFooter.baseURL=https://static.biodiversitydata.se
headerAndFooter.version=2
ala.baseURL=https://biodiversitydata.se
bie.baseURL=https://species.biodiversitydata.se
bie.searchPath=/search
collectoryUrl=https://collections.biodiversitydata.se

#skin.layout=
skin.orgNameLong=Swedish Biodiversity Data Infrastructure
skin.orgNameShort = SBDI
skin.orgSupportEmail=gbif@nrm.se
privacyPolicy=

#oidc related
security.cas.enabled=true
security.oidc.enabled=false
security.oidc.clientId=
security.oidc.secret=
security.oidc.discoveryUri=
security.jwt.enabled=false
security.jwt.discoveryUri=
33 changes: 33 additions & 0 deletions sbdi/make-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Get the last GitHub tag version
last_tag=$(git describe --tags --abbrev=0)

major=$(echo "$last_tag" | cut -d. -f1)
minor=$(echo "$last_tag" | cut -d. -f2)
patch=$(echo "$last_tag" | cut -d. -f3)

new_patch=$((patch + 1))

echo
read -p "Current version: $last_tag. Enter the new version (or press Enter for $major.$minor.$new_patch): " new_version_input

if [ -z "$new_version_input" ]; then
new_version="$major.$minor.$new_patch"
else
new_version="$new_version_input"
fi

# Validate the new version format (assuming it follows semantic versioning)
if ! [[ "$new_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Please use semantic versioning (e.g., 1.2.3)."
exit 1
fi

echo "Updating to version $new_version"

# Create a new tag
git tag "$new_version"
git push origin "$new_version"

echo "Tag $new_version created and pushed."

0 comments on commit c79bf52

Please sign in to comment.