Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target/
.git/
.github/
.gitignore
*.md
84 changes: 84 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Docker

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main
workflow_run:
workflows: ["CI"]
types:
- completed
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
if: >
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
github.event_name == 'pull_request'
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Smoke test - verify container starts
run: |
IMAGE_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
docker run --rm "$IMAGE_TAG"

- name: Build and push Docker image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
dependency-reduced-pom.xml
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Build stage: compile and package with Maven
FROM eclipse-temurin:17-jdk-alpine AS builder

WORKDIR /build

# Copy Maven configuration first for layer caching
COPY pom.xml .
RUN apk add --no-cache maven \
&& mvn dependency:go-offline -B

# Copy source and build
COPY src ./src
RUN mvn package -DskipTests -q

# Runtime stage: minimal JRE image
FROM eclipse-temurin:17-jre-alpine

LABEL org.opencontainers.image.title="NDArray Library Demo" \
org.opencontainers.image.description="NumPy-inspired array library for Java - Feature Demo" \
org.opencontainers.image.source="https://github.com/sMouaad/DevOps-Project" \
org.opencontainers.image.vendor="sadisamir"

WORKDIR /app

# Copy the built JAR from builder stage
COPY --from=builder /build/target/ndarray-library-*.jar ./ndarray-demo.jar

# Run the demo on container start
ENTRYPOINT ["java", "-jar", "ndarray-demo.jar"]
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NDArray Library (Java)

![CI](https://github.com/sMouaad/DevOps-Project/actions/workflows/ci.yml/badge.svg)
![Docker](https://github.com/sMouaad/DevOps-Project/actions/workflows/docker.yml/badge.svg)


Small NumPy-inspired Java library for ndarray operations, developed as a DevOps team project.
Expand Down Expand Up @@ -89,6 +90,45 @@ Planned CI quality hardening:

- Optional minimum coverage threshold gate once pipeline is stable.

## Docker

A demo container is available that showcases all NDArray features on startup.

### Quick Start (Pull and Run)

```bash
docker run --rm ghcr.io/smouaad/devops-project:main
```

### Build Locally

```bash
# Build the image
docker build -t ndarray-demo .

# Run the demo
docker run --rm ndarray-demo
```

### Image Tags

Images are published to GitHub Container Registry (`ghcr.io/smouaad/devops-project`):

| Tag | Description |
|-----|-------------|
| `main` | Latest build from main branch |
| `<version>` | Semantic version (e.g., `1.0.0`, `1.0`) |
| `<sha>` | Specific commit SHA |

### CI/CD Pipeline

The Docker workflow (`.github/workflows/docker.yml`):

- Builds on every push to `main` and version tags (`v*`)
- Validates builds on pull requests (no push)
- Uses multi-stage build for minimal image size
- Caches layers with GitHub Actions cache

## Current Status vs Mandatory Scope

Implemented:
Expand Down
44 changes: 44 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -50,6 +60,40 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>org.sadisamir.ndarray.demo.NdArrayDemo</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.sadisamir.ndarray.demo.NdArrayDemo</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Loading
Loading