diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9956d7c..2f462d6 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:23-noble +FROM eclipse-temurin:21-jammy RUN apt-get update && apt-get -y install \ maven git tree diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..da23e86 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,36 @@ +name: Build OCI image +on: push +jobs: + Build: + runs-on: ubuntu-latest + env: + IMAGE: ghcr.io/${{ github.repository }} + permissions: + attestations: write + contents: read + id-token: write + packages: write + + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.IMAGE }} + + - uses: docker/bake-action@v5 + id: bake + with: + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} + push: true diff --git a/Dockerfile b/Dockerfile index 46ee792..865e993 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,12 @@ -# docker build -t spring-app . -# docker run --name spring-app -d -p 8080:8080 spring-app - -FROM maven:3.9.8-eclipse-temurin-21 as build +# docker run --name spring-boilerplate -d -p 8080:8080 spring-boilerplate +FROM maven:3.9.8-eclipse-temurin-21 AS build COPY pom.xml . RUN --mount=type=cache,target=/root/.m2,rw mvn -B dependency:go-offline COPY src src RUN --mount=type=cache,target=/root/.m2,rw mvn -B package -FROM eclipse-temurin:21 +FROM eclipse-temurin:21-jammy WORKDIR /app COPY --from=build target/*.jar ./app.jar @@ -25,4 +23,3 @@ ENTRYPOINT ["java", "-javaagent:/app/opentelemetry-javaagent.jar", "-jar", "app. EXPOSE 8080 HEALTHCHECK CMD curl -f http://0.0.0.0:8080/health || exit 1 - diff --git a/README.md b/README.md index 4c84873..04e586b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # Spring Boilerplate +## Building +Build using [buildx bake](https://docs.docker.com/build/bake/): + +`docker buildx bake` (From the project root) + ## Observability ### Commands to test open telemetry locally diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..74620cb --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,7 @@ +target "docker-metadata-action" {} + +target "default" { + inherits = ["docker-metadata-action"] + context = "." + dockerfile = "Dockerfile" +} \ No newline at end of file