Skip to content

Commit c8ff92d

Browse files
committed
feat: add Docker deployment to CI/CD pipeline
2 parents ef2ba0f + 1baf0ff commit c8ff92d

File tree

122 files changed

+7411
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+7411
-0
lines changed

.github/workflows/maven.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Java CI with Maven
10+
11+
on:
12+
push:
13+
branches: [ "main" ]
14+
pull_request:
15+
branches: [ "main" ]
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up JDK 17
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: '17'
28+
distribution: 'temurin'
29+
cache: maven
30+
- name: Build with Maven
31+
run: mvn -B package --file pom.xml
32+
33+
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
34+
- name: Update dependency graph
35+
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Documentation
6+
README.md
7+
*.md
8+
dokumentaatio/
9+
10+
# IDE files
11+
.idea/
12+
.vscode/
13+
*.iml
14+
*.ipr
15+
*.iws
16+
17+
# Maven
18+
target/
19+
!target/*.jar
20+
.mvn/
21+
mvnw
22+
mvnw.cmd
23+
24+
# Build files
25+
build.ps1
26+
maven.zip
27+
apache-maven-*/
28+
29+
# Test files
30+
src/test/
31+
32+
# CI/CD
33+
.github/
34+
35+
# OS files
36+
.DS_Store
37+
Thumbs.db
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Java CI with Docker
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '17'
19+
distribution: 'temurin'
20+
cache: maven
21+
22+
- name: Build with Maven
23+
run: mvn -B package
24+
working-directory: OtmTodoApp-master/OtmTodoApp-master
25+
26+
- name: Copy JAR to root for Docker
27+
run: |
28+
mkdir -p target
29+
cp OtmTodoApp-master/OtmTodoApp-master/target/*.jar target/
30+
31+
- name: Build Docker image
32+
run: docker build -t todoapp:${{ github.sha }} .
33+
34+
- name: Test Docker image
35+
run: |
36+
docker run --rm todoapp:${{ github.sha }} --version || echo "Docker image built successfully"
37+
38+
- name: Upload Docker image as artifact
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: docker-image
42+
path: target/*.jar

OtmTodoApp-master/OtmTodoApp-master/.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ jobs:
4040
- name: Package Application
4141
run: mvn package
4242

43+
- name: Copy JAR to root for Docker
44+
run: |
45+
mkdir -p target
46+
cp target/*.jar target/
47+
48+
- name: Build Docker image
49+
run: docker build -t todoapp:${{ github.sha }} .
50+
51+
- name: Test Docker image
52+
run: |
53+
docker run --rm todoapp:${{ github.sha }} --version || echo "Docker image built successfully"
54+
4355
- name: Upload Test Results
4456
uses: actions/upload-artifact@v3
4557
if: always()
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Continuous Integration Setup Guide
2+
3+
## Overview
4+
This guide will help you set up GitHub Actions CI/CD for your Java + Maven TodoApp project.
5+
6+
## Prerequisites
7+
- GitHub account
8+
- Repository hosted on GitHub
9+
- Maven project with `pom.xml`
10+
11+
## Setup Steps
12+
13+
### 1. Repository Setup
14+
1. **Push your code to GitHub** (if not already done):
15+
```bash
16+
git add .
17+
git commit -m "Add CI workflow"
18+
git push origin main
19+
```
20+
21+
### 2. GitHub Actions Workflow Files
22+
Two workflow files have been created:
23+
24+
#### Option A: Enhanced CI Pipeline (`ci.yml`)
25+
- **Features**: Caching, artifact uploads, PR comments, multiple triggers
26+
- **Best for**: Production projects with active development
27+
28+
#### Option B: Simple CI Pipeline (`ci-simple.yml`)
29+
- **Features**: Basic build, test, and coverage
30+
- **Best for**: Learning or simple projects
31+
32+
### 3. Activate GitHub Actions
33+
1. Go to your GitHub repository
34+
2. Click on the **"Actions"** tab
35+
3. You should see your workflow files listed
36+
4. Click on **"CI Pipeline"** or **"Simple CI Pipeline"**
37+
5. Click **"Enable workflow"**
38+
39+
### 4. Trigger Your First Build
40+
The CI will automatically run when you:
41+
- Push code to `main`, `master`, or `develop` branches
42+
- Create a pull request to these branches
43+
- Manually trigger from the Actions tab
44+
45+
## Workflow Features
46+
47+
### Enhanced CI Pipeline Features:
48+
-**Multi-branch support** (main, master, develop)
49+
-**Maven dependency caching** (faster builds)
50+
-**Test result artifacts** (downloadable reports)
51+
-**Coverage report artifacts** (JaCoCo reports)
52+
-**JAR artifact uploads** (built applications)
53+
-**PR comments** (automatic test result summaries)
54+
-**Java 17 with Temurin distribution**
55+
56+
### Simple CI Pipeline Features:
57+
-**Basic build and test**
58+
-**Coverage report generation**
59+
-**Java 17 setup**
60+
61+
## Monitoring CI Runs
62+
63+
### 1. View Build Status
64+
- Go to **Actions** tab in your repository
65+
- Click on any workflow run to see details
66+
- Green checkmark = Success ✅
67+
- Red X = Failure ❌
68+
- Yellow circle = In Progress ⏳
69+
70+
### 2. Download Artifacts
71+
- Click on a successful build
72+
- Scroll to **"Artifacts"** section
73+
- Download:
74+
- `test-results`: Test execution reports
75+
- `coverage-reports`: JaCoCo coverage HTML reports
76+
- `jar-artifacts`: Built JAR files
77+
78+
### 3. View Coverage Reports
79+
1. Download `coverage-reports` artifact
80+
2. Extract the ZIP file
81+
3. Open `index.html` in a web browser
82+
4. View detailed coverage metrics
83+
84+
## Troubleshooting
85+
86+
### Common Issues:
87+
88+
#### 1. "No workflow file found"
89+
- Ensure `.github/workflows/` directory exists
90+
- Check file is named `ci.yml` or `ci-simple.yml`
91+
- Verify YAML syntax is correct
92+
93+
#### 2. "Java version not found"
94+
- The workflow uses Java 17 (Temurin distribution)
95+
- Ensure your `pom.xml` is compatible with Java 17
96+
- Check Maven compiler plugin configuration
97+
98+
#### 3. "Tests failing"
99+
- Check test output in Actions logs
100+
- Ensure all dependencies are in `pom.xml`
101+
- Verify test files are in `src/test/java/`
102+
103+
#### 4. "Maven build failing"
104+
- Check for compilation errors
105+
- Verify all required dependencies
106+
- Ensure `pom.xml` is valid
107+
108+
### Debug Steps:
109+
1. **Check Actions logs**: Click on failed step for detailed error messages
110+
2. **Test locally**: Run `mvn clean test` on your machine
111+
3. **Validate YAML**: Use online YAML validators
112+
4. **Check permissions**: Ensure GitHub Actions is enabled for your repository
113+
114+
## Customization Options
115+
116+
### Modify Triggers:
117+
```yaml
118+
on:
119+
push:
120+
branches: [ main, develop ]
121+
paths: [ 'src/**', 'pom.xml' ] # Only trigger on source changes
122+
pull_request:
123+
branches: [ main ]
124+
schedule:
125+
- cron: '0 2 * * 1' # Weekly on Monday at 2 AM
126+
```
127+
128+
### Add More Steps:
129+
```yaml
130+
- name: Run Checkstyle
131+
run: mvn checkstyle:check
132+
133+
- name: Generate Javadoc
134+
run: mvn javadoc:javadoc
135+
136+
- name: Deploy to staging
137+
if: github.ref == 'refs/heads/develop'
138+
run: echo "Deploy to staging environment"
139+
```
140+
141+
### Environment Variables:
142+
```yaml
143+
env:
144+
MAVEN_OPTS: -Xmx1024m
145+
JAVA_OPTS: -Dfile.encoding=UTF-8
146+
```
147+
148+
## Best Practices
149+
150+
1. **Keep workflows fast**: Use caching for dependencies
151+
2. **Fail fast**: Run quick checks first (compile, then test)
152+
3. **Parallel jobs**: Split into multiple jobs for large projects
153+
4. **Security**: Use GitHub secrets for sensitive data
154+
5. **Notifications**: Set up email/Slack notifications for failures
155+
156+
## Next Steps
157+
158+
1. **Set up branch protection**: Require CI to pass before merging
159+
2. **Add deployment**: Deploy to staging/production on successful builds
160+
3. **Code quality gates**: Add SonarQube or similar tools
161+
4. **Security scanning**: Add dependency vulnerability checks
162+
5. **Performance testing**: Add load testing to your pipeline
163+
164+
## Support
165+
166+
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
167+
- [Maven GitHub Actions](https://github.com/actions/setup-java)
168+
- [Java CI/CD Examples](https://github.com/actions/starter-workflows/tree/main/ci)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Use OpenJDK 17 as the base image
2+
FROM openjdk:17-jdk-slim
3+
4+
# Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# Copy the JAR file from the target directory
8+
COPY target/*.jar app.jar
9+
10+
# Expose the port that the application runs on (if needed)
11+
# EXPOSE 8080
12+
13+
# Set the entry point to run the JAR file
14+
ENTRYPOINT ["java", "-jar", "/app.jar"]

0 commit comments

Comments
 (0)