From 669b96f57fe513ea904f26a9605214aeb9e2099f Mon Sep 17 00:00:00 2001 From: Mats Bovin Date: Thu, 7 Sep 2023 16:05:55 +0200 Subject: [PATCH] Add README, make-release and build workflow. Tweaked Docker file --- .github/workflows/build.yml | 59 +++++++++++++++++++++++++++++++++++++ Dockerfile | 2 +- sbdi/README.md | 35 ++++++++++++++++++++++ sbdi/make-release.sh | 33 +++++++++++++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 sbdi/README.md create mode 100755 sbdi/make-release.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..ed57886d --- /dev/null +++ b/.github/workflows/build.yml @@ -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 }} diff --git a/Dockerfile b/Dockerfile index 4301bd1a..13b1f32f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM tomcat:9.0-jdk11-temurin -RUN mkdir -p /data/collectory/config +RUN mkdir -p /data/logger/config COPY build/libs/logger-service-*-plain.war $CATALINA_HOME/webapps/ROOT.war diff --git a/sbdi/README.md b/sbdi/README.md new file mode 100644 index 00000000..54621dfb --- /dev/null +++ b/sbdi/README.md @@ -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. +``` diff --git a/sbdi/make-release.sh b/sbdi/make-release.sh new file mode 100755 index 00000000..a72d5db8 --- /dev/null +++ b/sbdi/make-release.sh @@ -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."