Skip to content

Commit fd8359a

Browse files
authored
Merge pull request #26 from ikochuev/lesson28
lesson28: Full CI Pipeline
2 parents 3cd1bbd + 51cce1b commit fd8359a

18 files changed

Lines changed: 219 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: CI Pipeline Lesson28
2+
3+
on:
4+
push:
5+
branches: [ main, lesson28 ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
app: [hello-world, hello-jenkins, hello-devops]
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Java 17
19+
uses: actions/setup-java@v4
20+
with:
21+
java-version: '17'
22+
distribution: 'temurin'
23+
cache: 'maven'
24+
25+
- name: Test ${{ matrix.app }}
26+
run: mvn -B test --file lesson28/${{ matrix.app }}/pom.xml
27+
28+
- name: Build ${{ matrix.app }}
29+
run: mvn -B package -DskipTests --file lesson28/${{ matrix.app }}/pom.xml
30+
31+
- name: Upload ${{ matrix.app }} JAR
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: ${{ matrix.app }}-jar
35+
path: lesson28/${{ matrix.app }}/target/*.jar
36+
37+
docker-build-push:
38+
runs-on: ubuntu-latest
39+
needs: build-test
40+
strategy:
41+
matrix:
42+
app: [hello-world, hello-jenkins, hello-devops]
43+
permissions:
44+
contents: read
45+
packages: write
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- name: Download ${{ matrix.app }} JAR
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: ${{ matrix.app }}-jar
53+
path: lesson28/${{ matrix.app }}/target/
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Login to GHCR
59+
uses: docker/login-action@v3
60+
with:
61+
registry: ghcr.io
62+
username: ${{ github.actor }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Build and push ${{ matrix.app }}
66+
uses: docker/build-push-action@v6
67+
with:
68+
context: lesson28/${{ matrix.app }}/
69+
push: true
70+
tags: |
71+
ghcr.io/ikochuev/codeby-devops-${{ matrix.app }}:${{ github.sha }}
72+
ghcr.io/ikochuev/codeby-devops-${{ matrix.app }}:latest

lesson28/.dockerignore

34 Bytes
Binary file not shown.

lesson28/hello-devops/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM maven:3.8-openjdk-17 AS build
2+
WORKDIR /app
3+
COPY pom.xml .
4+
RUN mvn dependency:go-offline -B
5+
COPY src src
6+
RUN mvn clean package -DskipTests
7+
8+
FROM eclipse-temurin:17-jre
9+
WORKDIR /app
10+
COPY --from=build /app/target/*.jar app.jar
11+
ENTRYPOINT ["java", "-jar", "app.jar"]

lesson28/hello-devops/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.mycompany.app</groupId>
5+
<artifactId>hello-devops</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<properties>
8+
<maven.compiler.source>17</maven.compiler.source>
9+
<maven.compiler.target>17</maven.compiler.target>
10+
</properties>
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.junit.jupiter</groupId>
14+
<artifactId>junit-jupiter</artifactId>
15+
<version>5.10.0</version>
16+
<scope>test</scope>
17+
</dependency>
18+
</dependencies>
19+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.mycompany.app;
2+
public class App {
3+
private static final String MESSAGE = "Hello Devops!";
4+
public App() {}
5+
public static void main(String[] args) { System.out.println(MESSAGE); }
6+
public String getMessage() { return MESSAGE; }
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.mycompany.app;
2+
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
public class AppTest {
5+
@Test void testAppConstructor() {
6+
App app1 = new App(); App app2 = new App();
7+
assertEquals(app1.getMessage(), app2.getMessage());
8+
}
9+
@Test void testAppMessage() {
10+
assertEquals("Hello Devops!", new App().getMessage());
11+
}
12+
}

lesson28/hello-jenkins/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM maven:3.8-openjdk-17 AS build
2+
WORKDIR /app
3+
COPY pom.xml .
4+
RUN mvn dependency:go-offline -B
5+
COPY src src
6+
RUN mvn clean package -DskipTests
7+
8+
FROM eclipse-temurin:17-jre
9+
WORKDIR /app
10+
COPY --from=build /app/target/*.jar app.jar
11+
ENTRYPOINT ["java", "-jar", "app.jar"]

lesson28/hello-jenkins/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.mycompany.app</groupId>
5+
<artifactId>hello-jenkins</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<properties>
8+
<maven.compiler.source>17</maven.compiler.source>
9+
<maven.compiler.target>17</maven.compiler.target>
10+
</properties>
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.junit.jupiter</groupId>
14+
<artifactId>junit-jupiter</artifactId>
15+
<version>5.10.0</version>
16+
<scope>test</scope>
17+
</dependency>
18+
</dependencies>
19+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.mycompany.app;
2+
public class App {
3+
private static final String MESSAGE = "Hello Jenkins!";
4+
public App() {}
5+
public static void main(String[] args) { System.out.println(MESSAGE); }
6+
public String getMessage() { return MESSAGE; }
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.mycompany.app;
2+
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
public class AppTest {
5+
@Test void testAppConstructor() {
6+
App app1 = new App(); App app2 = new App();
7+
assertEquals(app1.getMessage(), app2.getMessage());
8+
}
9+
@Test void testAppMessage() {
10+
assertEquals("Hello Jenkins!", new App().getMessage());
11+
}
12+
}

0 commit comments

Comments
 (0)