diff --git a/.github/workflows/build_deploy_dev.yml b/.github/workflows/build_deploy_dev.yml new file mode 100644 index 0000000..5f11fb3 --- /dev/null +++ b/.github/workflows/build_deploy_dev.yml @@ -0,0 +1,33 @@ +name: build and publish docker image / deploy + +on: + push: + branches: ["dev"] + pull_request: + branches: ["dev"] + + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: https://github.com/actions/checkout@v4 + with: + repository: 'learningpulse/server' + ref: 'dev' + token: '${{ secrets.token }}' + - name: 'Set up java 22' + uses: https://github.com/actions/setup-java@v3 + with: + java-version: "22" + distribution: "temurin" + + - name: "Setup maven" + uses: https://github.com/stCarolas/setup-maven@v5 + + - name: Build with Maven + run: mvn -Dtoken=${{ secrets.token }} clean compile jib:build -e + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7141f51 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result/* +result \ No newline at end of file diff --git a/flake.lock b/flake.lock index e6e6355..8af82e3 100644 --- a/flake.lock +++ b/flake.lock @@ -2,18 +2,17 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1716293225, - "narHash": "sha256-pU9ViBVE3XYb70xZx+jK6SEVphvt7xMTbm6yDIF4xPs=", - "owner": "nixos", + "lastModified": 1716509168, + "narHash": "sha256-4zSIhSRRIoEBwjbPm3YiGtbd8HDWzFxJjw5DYSDy1n8=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "3eaeaeb6b1e08a016380c279f8846e0bd8808916", + "rev": "bfb7a882678e518398ce9a31a881538679f6f092", "type": "github" }, "original": { - "owner": "nixos", + "id": "nixpkgs", "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" + "type": "indirect" } }, "root": { diff --git a/flake.nix b/flake.nix index 538215b..4711d3e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,48 +1,95 @@ { - description = "Learning Pulse"; - + description = "CI, devshell and package definition for learningpulse"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + nixpkgs.url = "nixpkgs/nixos-unstable"; }; - - outputs = - { self - , nixpkgs - , maven - , makeWrapper - }: + outputs = { self, nixpkgs, ... }: let - javaVersion = 22; - overlays = [ - (final: prev: rec { - jdk = prev."jdk${toString javaVersion}"; - gradle = prev.gradle.override { java = jdk; }; - maven = prev.maven.override { inherit jdk; }; - }) - ]; - supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { - pkgs = import nixpkgs { inherit overlays system; }; - }); + # TODO add more systems + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + buildPackages = with pkgs; [ + jdk22 + makeWrapper + ]; in - { - hydraJobs = { - gateway = maven.buildMavenPackage rec { - pname = "learningpulse-gateway"; - version = "1.2.1"; - # - # hello i wrote something here to test pulling + rec { + packages.${system} = + { + learningpulse-gateway = pkgs.maven.buildMavenPackage rec { + pname = "gateway"; + version = "0.0.1"; + + src = ./.; + # todo get automatically + mvnHash = "sha256-YCK1Qujgx73cZdEx2mRip+y+66px5TxL247fBIMyoy4="; + + nativeBuildInputs = buildPackages; + + installPhase = '' + mkdir -p $out/bin $out/share/${pname} + install -Dm644 ${pname}/target/${pname}-${version}.jar $out/share/${pname} + + makeWrapper ${pkgs.jre8}/bin/java $out/bin/${pname} \ + --add-flags "-jar $out/share/${pname}/${pname}-${version}.jar" + ''; + }; + + learningpulse-eureka = pkgs.maven.buildMavenPackage rec { + pname = "eureka"; + version = "0.0.1"; + + src = ./.; + # todo get automatically + mvnHash = "sha256-YCK1Qujgx73cZdEx2mRip+y+66px5TxL247fBIMyoy4="; + + nativeBuildInputs = buildPackages; + + installPhase = '' + mkdir -p $out/bin $out/share/${pname} + install -Dm644 ${pname}/target/${pname}-${version}.jar $out/share/${pname} + + makeWrapper ${pkgs.jre8}/bin/java $out/bin/${pname} \ + --add-flags "-jar $out/share/${pname}/${pname}-${version}.jar" + ''; + }; + + learningpulse-dummy = pkgs.maven.buildMavenPackage rec { + pname = "dummy"; + version = "0.0.1"; + + src = ./.; + # todo get automatically + mvnHash = "sha256-YCK1Qujgx73cZdEx2mRip+y+66px5TxL247fBIMyoy4="; + + nativeBuildInputs = buildPackages; + installPhase = '' + mkdir -p $out/bin $out/share/${pname} + install -Dm644 ${pname}/target/${pname}-${version}.jar $out/share/${pname} + + makeWrapper ${pkgs.jre8}/bin/java $out/bin/${pname} \ + --add-flags "-jar $out/share/${pname}/${pname}-${version}.jar" + ''; + + }; }; + + + hydraJobs = { + inherit (self) + packages; }; - devShells = forEachSupportedSystem ({ pkgs }: { - default = pkgs.mkShell { - packages = with pkgs; [ - jdk - maven - ]; - }; - }); + devShells."${system}".default = pkgs.mkShell { + buildInputs = with pkgs; [ + maven + jdk22 + jre8 + # top run actions locally + act + ]; + }; }; + } diff --git a/pom.xml b/pom.xml index 2cf3142..a083ab6 100644 --- a/pom.xml +++ b/pom.xml @@ -61,12 +61,51 @@ - + org.springframework.boot spring-boot-maven-plugin + + com.google.cloud.tools + jib-maven-plugin + 3.4.2 + + + eclipse-temurin:22-jre + + + + amd64 + linux + + + arm64 + linux + + + + + git.4o1x5.dev/learningpulse/server/${project.artifactId}:${project.version} + + hydrabot + ${token} + + + + + + package + + dockerBuild + + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a6fde47 --- /dev/null +++ b/readme.md @@ -0,0 +1,23 @@ +# LearningPulse server + +## CI/CD + +To check up on builds head to [the hydra server](https://hydra.4o1x5.dev/project/learningpulse) + +### Enter developer shell + +```bash +nix develop +``` + +### Build services + +```bash +nix build .#learningpulse-dummy +``` + +### Run service + +```bash +nix develop && cd dummy && mvn run spring-boot:run +```