From a8c692e8de25dbd1300531f13b1ab388d34aaf3b Mon Sep 17 00:00:00 2001 From: Ashutosh Gangwar Date: Wed, 25 Oct 2023 13:01:34 +0530 Subject: [PATCH] clinic: add build job to the github workflow --- .github/workflows/clinic.yaml | 68 +++++++++++++++++++++++++++++++++- clinic/Dockerfile | 4 ++ clinic/project.clj | 2 +- clinic/src/clj/clinic/core.clj | 3 +- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 clinic/Dockerfile diff --git a/.github/workflows/clinic.yaml b/.github/workflows/clinic.yaml index ee293cd..b22a93d 100644 --- a/.github/workflows/clinic.yaml +++ b/.github/workflows/clinic.yaml @@ -13,7 +13,8 @@ on: env: JDK_DISTRIBUTION: temurin - JAVA_VERSION: 17 + JAVA_VERSION: 21 + NODE_VERSION: 21 jobs: tests: @@ -40,6 +41,11 @@ jobs: with: distribution: ${{ env.JDK_DISTRIBUTION }} java-version: ${{ env.JAVA_VERSION }} + - name: Setup Lein Dependency Cache + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-lein-${{ hashFiles('clinic/project.clj') }} # can't use `services.[id].options` to add Docker health checks because # HAPI has a scratch docker image without a shell installation. @@ -47,3 +53,63 @@ jobs: run: while ! curl -sSI "http://localhost:8090"; do sleep 5; done - name: Run Tests run: lein test + + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 10 + if: github.event_name == 'push' # skip for pull requests. + needs: + - tests + permissions: + contents: read + packages: write + defaults: + run: + working-directory: ./clinic + steps: + - name: Checkout Source + uses: actions/checkout@v4 + - name: Setup JDK + uses: actions/setup-java@v3 + with: + distribution: ${{ env.JDK_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: npm + cache-dependency-path: clinic/package-lock.json + - name: Setup Lein Dependency Cache + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-lein-${{ hashFiles('clinic/project.clj') }} + - name: Build CLJS + run: | + npm install + npx shadow-cljs release app + - name: Build Uberjar + run: lein uberjar + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Generate Docker Image Tags + id: docker-image-tags + run: | + image_name=ghcr.io/nilenso/ashutosh-onboarding/clinic + image_tags="${image_name}:latest" + if [[ "$GITHUB_REF" =~ refs/tags/* ]]; then + image_tags="${image_tags},${image_name}:${{ github.ref_name }}" + fi + echo "tags=$image_tags" >> "$GITHUB_OUTPUT" + - name: Build and Push Latest Docker Image + uses: docker/build-push-action@v5 + with: + context: clinic + push: true + tags: ${{ steps.docker-image-tags.outputs.tags }} diff --git a/clinic/Dockerfile b/clinic/Dockerfile new file mode 100644 index 0000000..88d1d49 --- /dev/null +++ b/clinic/Dockerfile @@ -0,0 +1,4 @@ +FROM eclipse-temurin:21-jre +LABEL org.opencontainers.image.source="https://github.com/nilenso/ashutosh-onboarding" +COPY target/uberjar/clinic-latest-standalone.jar /app.jar +CMD ["java", "-jar", "/app.jar"] diff --git a/clinic/project.clj b/clinic/project.clj index c1a2061..45b1584 100644 --- a/clinic/project.clj +++ b/clinic/project.clj @@ -1,4 +1,4 @@ -(defproject clinic "0.1.0-SNAPSHOT" +(defproject clinic "latest" :description "Onboarding project #2" :url "https://github.com/nilenso/ashutosh-onboarding/blob/main/clinic" :dependencies [[aero "1.1.6"] diff --git a/clinic/src/clj/clinic/core.clj b/clinic/src/clj/clinic/core.clj index 9353136..e32f2cb 100644 --- a/clinic/src/clj/clinic/core.clj +++ b/clinic/src/clj/clinic/core.clj @@ -2,7 +2,8 @@ (:require [clinic.config :as config] [clinic.routes.core :as routes] [mount.core :as mount] - [ring.adapter.jetty :as jetty])) + [ring.adapter.jetty :as jetty]) + (:gen-class)) (defonce server (atom nil))