Skip to content

Commit

Permalink
Dockerized and github action
Browse files Browse the repository at this point in the history
  • Loading branch information
KTMetcalfe committed Oct 30, 2023
1 parent 8fa0b7c commit e99e5d5
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
Dockerfile*
docker-compose*
.git
.gitignore
README.md
.vscode
target
build
41 changes: 41 additions & 0 deletions .github/workflows/docker_build_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Docker Build, Test & Push

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and Test
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
tags: web-backend:latest
push: false

- name: Login to Google Artifact Registry
uses: docker/login-action@v1
with:
registry: us-east5-docker.pkg.dev
username: _json_key
password: ${{ secrets.GAR_KEY }}

- name: Push to Google Artifact Registry
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
tags: us-east5-docker.pkg.dev/wheelshare-webapp/wheelshare/web-backend:latest
push: true
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ----- Build Stage -----
FROM maven:3.9.4-eclipse-temurin-17-alpine AS builder

WORKDIR /app

# Copy the pom.xml file
COPY pom.xml .

# Download dependencies
RUN mvn dependency:go-offline -B

# Copy the source code
COPY src src

# Build the project
RUN mvn package

# ----- Run Stage -----
FROM openjdk:17-jdk-alpine AS runtime

WORKDIR /app

# Copy the jar file from the builder stage
COPY --from=builder /app/target/my-path-back-end-*.jar app.jar

# Copy the map download script
COPY downloadMap.sh .

# Make map download script executable
RUN chmod +x downloadMap.sh

# Create a cron job to run the map download script every 5 minutes
RUN echo "*/5 * * * * /app/downloadMap.sh" > /etc/crontabs/root

# Expose API port
EXPOSE 8081

# Run the jar file
CMD ["/bin/sh", "-c", "/app/downloadMap.sh && crond && exec java -jar app.jar"]
12 changes: 12 additions & 0 deletions downloadMap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#This script downloads the OSM data by hitting the Overpass API

#Set default bounding box
minLon=-84.7872
maxLon=-84.6941
minLat=39.4929
maxLat=39.5209

echo "Downloading OSM data for bounding box: $minLon,$minLat,$maxLon,$maxLat"

wget -O ./mapData.json "https://overpass-api.de/api/interpreter?data=[out:json];(node($minLat,$minLon,$maxLat,$maxLon);<;);out%20meta;" && echo "Last Success Downloaded at $(date)" > "./map-download-history.txt"
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public void buildMap() {

// * Read the file in
// Local mapData location
Object jsonFileObject = parser.parse(new FileReader(absoluteFilePath +
"/src/main/resources/mapData.json"));
// Object jsonFileObject = parser.parse(new FileReader(absoluteFilePath +
// "/src/main/resources/mapData.json"));

// Server mapData location
// Object jsonFileObject = parser.parse(new FileReader(absoluteFilePath +
// "/mapData.json"));
Object jsonFileObject = parser.parse(new FileReader(absoluteFilePath +
"/mapData.json"));

JSONObject jsonObject = (JSONObject) jsonFileObject;

Expand Down

0 comments on commit e99e5d5

Please sign in to comment.