Skip to content

Commit

Permalink
WFPREV-145 - Initial Rest endpoints including projects (#326)
Browse files Browse the repository at this point in the history
Co-authored-by: Dylan Hemsworth <[email protected]>
Co-authored-by: Sean Sylver <[email protected]>
Co-authored-by: ssylver93 <[email protected]>
Co-authored-by: Chris Preston <[email protected]>
  • Loading branch information
5 people authored Dec 6, 2024
1 parent 577de38 commit 48f6f29
Show file tree
Hide file tree
Showing 80 changed files with 5,607 additions and 1,247 deletions.
126 changes: 62 additions & 64 deletions .github/workflows/mvn-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,64 +49,61 @@ jobs:
with:
ref: ${{ inputs.BRANCH }}

- name: Setup Maven
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'

- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
components: 'native-image'

- name: Add .npmrc file
run: echo -e $NPMRC > ~/.npmrc

- name: Build Native Image with Maven
if: ${{ inputs.COMPONENT_TYPE == 'server' }}
run: |
set -x
export MAVEN_OPTS="-Xmx6g -XX:MaxMetaspaceSize=1g"
export NATIVE_IMAGE_OPTS="-Xmx8g"
cd ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}
# Use absolute path to settings.xml
settings_file="$(pwd)/mvn_settings/settings.xml"
echo "Looking for settings file at: $settings_file"
# Check if file exists and is readable
if [ ! -f "$settings_file" ]; then
echo "ERROR: $settings_file not found!"
ls -la mvn_settings/
exit 1
fi
if [ ! -r "$settings_file" ]; then
echo "ERROR: $settings_file not readable!"
ls -la "$settings_file"
exit 1
fi
echo "Using settings file: $settings_file"
mvn -s "$settings_file" --batch-mode -Pnative native:compile -DskipTests -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }}
- name: Copy native binary to staging
if: ${{ inputs.COMPONENT_TYPE == 'server' }}
run: |
mkdir -p staging
cp ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}/target/wfprev-api staging/
- uses: actions/upload-artifact@v3
with:
name: ${{ inputs.COMPONENT_NAME }}-package
path: staging
# - name: Setup Maven
# uses: actions/setup-java@v4
# with:
# distribution: 'temurin'
# java-version: '21'
# cache: 'maven'
#
# - name: Setup GraalVM
# uses: graalvm/setup-graalvm@v1
# with:
# java-version: '21'
# distribution: 'graalvm-community'
# github-token: ${{ secrets.GITHUB_TOKEN }}
# native-image-job-reports: 'true'
# components: 'native-image'
#
# - name: Build Native Image with Maven
# if: ${{ inputs.COMPONENT_TYPE == 'server' }}
# run: |
# set -x
# export MAVEN_OPTS="-Xmx6g -XX:MaxMetaspaceSize=1g"
# export NATIVE_IMAGE_OPTS="-Xmx8g"
# cd ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}
#
# # Use absolute path to settings.xml
# settings_file="$(pwd)/mvn_settings/settings.xml"
# echo "Looking for settings file at: $settings_file"
#
# # Check if file exists and is readable
# if [ ! -f "$settings_file" ]; then
# echo "ERROR: $settings_file not found!"
# ls -la mvn_settings/
# exit 1
# fi
#
# if [ ! -r "$settings_file" ]; then
# echo "ERROR: $settings_file not readable!"
# ls -la "$settings_file"
# exit 1
# fi
#
# echo "Using settings file: $settings_file"
# mvn -s "$settings_file" --batch-mode -Pnative native:compile -DskipTests -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }}
#
#
# - name: Copy native binary to staging
# if: ${{ inputs.COMPONENT_TYPE == 'server' }}
# run: |
# mkdir -p staging
# cp ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}/target/wfprev-api staging/
#
# - uses: actions/upload-artifact@v3
# with:
# name: ${{ inputs.COMPONENT_NAME }}-package
# path: staging

docker:
needs: build
Expand All @@ -126,11 +123,11 @@ jobs:
trimTag="${branchTag##*/}"
echo "BRANCH_TAG=$trimTag" >> $GITHUB_OUTPUT
- name: download native binary
uses: actions/download-artifact@v3
with:
name: ${{ inputs.COMPONENT_NAME }}-package
path: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}}
# - name: download native binary
# uses: actions/download-artifact@v4
# with:
# name: ${{ inputs.COMPONENT_NAME }}-package
# path: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down Expand Up @@ -159,11 +156,12 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}}
file: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}}/Dockerfile.graalvm
build-args: |
CONTAINER_NAME=${{inputs.COMPONENT_NAME}}
MAVEN_SETTINGS_FILE=settings.xml
REPO_LOGIN=${{secrets.IDIR_AS_EMAIL}}
REPO_PASSWORD=${{secrets.IDIR_PASSWORD}}
push: true
tags: ${{ steps.meta_pr.outputs.tags }}
labels: ${{ steps.meta_pr.outputs.labels }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
htmlReport/
/target
/.vscode
/.idea
Expand All @@ -9,4 +10,4 @@
**/.env
**/.env.*
.DS_Store
**/.DS_Store
**/.DS_Store
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ The goal of the BC Wildfire Service (BCWS) Prevention Program is to reduce the n

## Getting Started

## FOR CONVENIENCE

You can bring up the full system including the database, liquibase and the backend service with the following command:

```docker compose up```

That's it!

### Local Deployment

For local development, we recommend starting individual services with Docker
Expand Down Expand Up @@ -56,3 +64,4 @@ POSTGRES_PASSWORD=***
```

[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](<Redirect-URL>)

6 changes: 3 additions & 3 deletions client/wfprev-war/src/main/angular/.github/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v4

Expand All @@ -22,7 +22,7 @@ jobs:
node-version: ${{ matrix.node-version }}

- run: npm install

- run: npm run test -- --watch=false --code-coverage

# Ensure coverage meets the required threshold
Expand All @@ -33,4 +33,4 @@ jobs:
else
echo "Code coverage is less than 80%!";
exit 1;
fi
fi
72 changes: 72 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
services:
api:
build:
context: .
dockerfile: server/wfprev-api/Dockerfile.graalvm
# Pass the maven settings file and repo credentials as build args
args:
- MAVEN_SETTINGS_FILE=vivid.settings.xml
- REPO_LOGIN=${REPO_LOGIN}
- REPO_PASSWORD=${REPO_PASSWORD}
environment:
# Environment variables for the application
WFPREV_DATASOURCE_URL: ${WFPREV_DATASOURCE_URL}
WFPREV_DATASOURCE_USERNAME: ${WFPREV_DATASOURCE_USERNAME}
WFPREV_DATASOURCE_PASSWORD: ${WFPREV_DATASOURCE_PASSWORD}
ports:
- "8080:8080" # Map the API's port to the host
depends_on:
db:
condition: service_healthy
networks:
- wfprev-network
env_file:
- .env

liquibase:
build:
context: db
dockerfile: Dockerfile.liquibase.local
command: [
"liquibase",
"--url=jdbc:postgresql://wfprev-postgres:5432/wfprev",
"--changelog-file=db/main-changelog.json",
"--username=wfprev",
"--password=${POSTGRES_PASSWORD}",
"update"
]
volumes:
- ./db:/liquibase/db
depends_on:
db:
condition: service_healthy
networks:
- wfprev-network

db:
image: postgis/postgis:16-3.4
container_name: wfprev-postgres
environment:
POSTGRES_USER: wfprev
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: wfprev
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- wfprev-network
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U wfprev -d wfprev" ]
interval: 5s
timeout: 5s
retries: 5
start_period: 10s

networks:
wfprev-network:
driver: bridge

volumes:
postgres_data:
driver: local
2 changes: 1 addition & 1 deletion server/wfprev-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ build/
!**/src/test/**/build/

### VS Code ###
.vscode/
.vscode/
52 changes: 52 additions & 0 deletions server/wfprev-api/Dockerfile.agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Build stage
FROM ghcr.io/graalvm/graalvm-community:21 AS builder

# Define build argument and set it as environment variable
ARG MAVEN_SETTINGS_FILE=settings.xml

ENV MAVEN_SETTINGS_FILE=${MAVEN_SETTINGS_FILE}

# The environment variables from .env are automatically available here
# We don't need the ARG declarations anymore since we're using the env file

WORKDIR /app

# Copy maven settings first
COPY mvn_settings/${MAVEN_SETTINGS_FILE} /root/.m2/settings.xml

# Copy rest of the application
COPY . /app

# Make mvnw executable
RUN chmod +x mvnw

# Create the directory for GraalVM agent metadata and set permissions
RUN mkdir -p /app/META-INF/native-image
RUN chmod -R 777 /app/META-INF/native-image

# Run the GraalVM agent during the build stage
RUN java -agentlib:native-image-agent=config-output-dir=META-INF/native-image \
-Dspring.profiles.active=graalvm-agent \
-jar target/wfprev-api-1.0.0-SNAPSHOT.jar || true


# Build the native image using settings.xml
RUN ./mvnw -s mvn_settings/${MAVEN_SETTINGS_FILE} -Pnative native:compile

# Runtime stage
FROM ubuntu:22.04

# Install curl for healthcheck and debugging
RUN apt-get update && apt-get install -y \
libc6 \
libstdc++6 \
curl \
&& rm -rf /var/lib/apt/lists/*

# Copy the native executable from builder stage
COPY --from=builder /app/target/wfprev-api /

# Expose the port your application uses
EXPOSE 8080

ENTRYPOINT ["/wfprev-api"]
52 changes: 52 additions & 0 deletions server/wfprev-api/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Use Eclipse Temurin's Java 21 image as the base
FROM eclipse-temurin:21-jdk-jammy

# Set working directory
WORKDIR /app

# Install required utilities
RUN apt-get update && apt-get install -y \
curl \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*

# Copy Maven settings
ARG MAVEN_SETTINGS_FILE=settings.xml
COPY mvn_settings/${MAVEN_SETTINGS_FILE} /root/.m2/settings.xml

# Copy source code and Maven wrapper
COPY .mvn/ .mvn/
COPY mvnw pom.xml ./
RUN chmod +x mvnw

# Download dependencies separately to leverage Docker cache
RUN ./mvnw dependency:go-offline -s /root/.m2/settings.xml

# Copy the rest of the application
COPY src ./src/

# Expose ports for the application and debugging
EXPOSE 8080
EXPOSE 5005

# Create start script with debug options
COPY <<EOF /app/start.sh
#!/bin/sh
echo "==== Environment Variables ===="
echo "WFPREV_DATASOURCE_URL: \${WFPREV_DATASOURCE_URL}"
echo "WFPREV_DATASOURCE_USERNAME: \${WFPREV_DATASOURCE_USERNAME}"
echo "Database connection test:"

until pg_isready -h db -U \${WFPREV_DATASOURCE_USERNAME}; do
echo "Waiting for database connection..."
sleep 2
done

echo "Starting application in debug mode..."
exec ./mvnw spring-boot:run \
-Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
EOF

RUN chmod +x /app/start.sh

ENTRYPOINT ["/app/start.sh"]
Loading

0 comments on commit 48f6f29

Please sign in to comment.