Skip to content

Commit

Permalink
Added docker-build.yml which should build solarthing-server only
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Mar 21, 2023
1 parent dbfa67d commit 24e3a83
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# https://docs.github.com/en/actions/learn-github-actions/expressions
- if: ${{ matrix.language == 'java' }}
uses: actions/setup-node@v3
with:
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Create and publish a Docker image

on:
push:
branches:
- master

env:
REGISTRY: ghcr.io

jobs:
build-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: (cd web && npm install)
- name: Build Boot Jar
run: ./gradlew graphql:bootJar

# https://github.com/marketplace/actions/docker-login
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/marketplace/actions/docker-metadata-action
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
# images: ${{ env.REGISTRY }}/${{ github.actor }}/solarthing-server
images: ${{ env.REGISTRY }}/wildmountainfarms/solarthing-server
tags: |
type=raw,value=edge,enable=${{ github.ref == 'refs/heads/master' }}
# https://github.com/marketplace/actions/docker-setup-buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
file: docker/solarthing-server/Dockerfile
build-args:
- 'BOOT_JAR=graphql/build/libs/graphql-0.0.1-SNAPSHOT.jar'
push: true
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Custom stuff:
/test/
*.attach_pid*
.~lock*
*.log.gz
Expand Down
3 changes: 2 additions & 1 deletion .idea/dictionaries/lavender.xml

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

12 changes: 12 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# docker
This directory is used to contain `Dockerfile`s to build `solarthing` and `solarthing-server` docker images.
Note that this directory is designed to be separate from the state of a codebase at any given commit.
Even while building docker images for older SolarThing versions,
the latest files in this folder should be used to build those images.

So, the only Dockerfiles that should be used to build solarthing should be on the master branch of this repository.

```shell
# run in solarthing root
docker build -f docker/solarthing-server/Dockerfile --build-arg BOOT_JAR=graphql/build/libs/graphql-0.0.1-SNAPSHOT.jar --tag wildmountainfarms/solarthing-server:latest .
```
14 changes: 14 additions & 0 deletions docker/solarthing-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM eclipse-temurin:19-jre-jammy as builder
ARG BOOT_JAR
COPY ${BOOT_JAR} application.jar
RUN java -Djarmode=layertools -jar application.jar extract


FROM eclipse-temurin:19-jre-jammy
RUN ["mkdir", "/app"]
WORKDIR "/app"
COPY --from=builder dependencies/ ./
COPY --from=builder snapshot-dependencies/ ./
COPY --from=builder spring-boot-loader/ ./
COPY --from=builder application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
Empty file added docker/solarthing/Dockerfile
Empty file.
11 changes: 11 additions & 0 deletions graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ For testing your skills/syntax: https://graphql.org/swapi-graphql or https://nhz
Use `./gradlew graphql:bootJar` or [./graphql_compile_and_move.sh](../graphql_compile_and_move.sh) in the root directory.

Or `./gradlew graphql:bootRun` to run this

### Future `Dockerfile`

https://reflectoring.io/spring-boot-docker/

When we create a `Dockerfile` from the boot jar, we will want to extract its layers.

```shell
java -Djarmode=layertools -jar ../graphql/build/libs/graphql-0.0.1-SNAPSHOT.jar extract
# then copy the 4 folders to /app or something
```
20 changes: 18 additions & 2 deletions graphql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

version = '0.0.1-SNAPSHOT'
//project.ext.mainClass = "me.retrodaredevil.solarthing.graphql.SolarThingApplication" // This isn't doing anything?

compileJava {
// TODO We don't need the -parameters compiler argument (I don't think), plus now that Java 11 is required for GraphQL, what does it do/is it needed if we did need it?
options.compilerArgs << '-parameters' // we don't want to use have to put @GraphQLArgument everywhere
}

dependencies {
// implementation "com.fasterxml.jackson.module:jackson-module-jsonSchema:$jacksonVersion" // I don't remember why we needed this
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Expand All @@ -52,6 +50,24 @@ jar {
bootRun {
workingDir = new File("../program/graphql")
}
/*
If we want to in the future, we can apply the 'war' plugin and configure the war task to be enabled here.
We could then use bootWar to generate a war file to be used inside a tomcat server.
*/

/*
If we want to in the future, we can configure this.
However, configuring a buildpack (https://buildpacks.io/docs/operator-guide/create-a-builder/) is a learning curve.
The default buildpack setup actually works perfectly, but compiling to multiple architectures (platforms)
is actually a pain in the ass to find documentation on.
bootBuildImage {
// https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#build-image
// docker buildx create --use --platform linux/386,linux/amd64,linux/arm/v7,linux/arm64/v7,linux/ppc64le,linux/s390x
// https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#build-image.examples.custom-image-builder
def containerRegistry = "ghcr.io"
imageName = "$containerRegistry/wildmountainfarms/solarthing-server:latest"
}
*/

processResources {
dependsOn(":web:build")
Expand Down
10 changes: 6 additions & 4 deletions other/docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Packet for disk usage
* Send packet when mate serial port hasn't output data for 30 seconds
* Create Dockerfile and example docker-compose file
* We should use https://hub.docker.com/r/azul/zulu-openjdk
* We should use https://hub.docker.com/_/eclipse-temurin/tags?page=1&name=19-jre-jammy
* And for SolarThing server: https://hub.docker.com/_/tomcat/tags?page=1&name=jre17-temurin
* Short term record packets for high/low battery voltage, FX inverter current, pv wattage, charging current, etc
* This would be very useful so that if packets are replaced there is still information on how
high or low the battery voltage got or how high the load was
Expand All @@ -27,9 +28,6 @@ don't look like they're constantly disconnecting and reconnecting
* Possibly refactor PacketListReceiver
* Have a way to tell if a packet included in the packets list is important enough to warrant storing in the database.
* Right now we do a bunch of packets.isEmpty() checks to see if we should continue adding packets, but there's probably a better way
* Better way to update SNAPSHOT jar so that running SolarThing instances don't get mad
* We have a great setup for versioned SolarThing jar files, because running instances will still use
whatever jar solarthing.jar pointed them to originally, but this isn't the case when we actually change the jar it is pointing to
* Backend Grafana plugin to allow commands to be sent
* Might not actually need a backend plugin if we can just use the proxy instead
* https://github.com/grafana/grafana/issues/12556
Expand Down Expand Up @@ -203,6 +201,10 @@ easy displaying in Grafana
* Use https://github.com/tbroyer/gradle-errorprone-plugin
* Add info about the state of CouchDB on the home page of SolarThing web
* Add this to web: https://github.com/IvanGoncharov/graphql-voyager
* Better way to update SNAPSHOT jar so that running SolarThing instances don't get mad
* We have a great setup for versioned SolarThing jar files, because running instances will still use
whatever jar solarthing.jar pointed them to originally, but this isn't the case when we actually change the jar it is pointing to
* Completed a while ago with SNAPSHOT-1 and SNAPSHOT-2 alternating

### Look into
* Look into supporting Elasticsearch, MongoDB, Graphite
Expand Down

0 comments on commit 24e3a83

Please sign in to comment.