Skip to content

Commit d15b3e5

Browse files
PiachseckiPiasecki-gridxederro
authored
Adding first pipeline to the project (#6)
* Added building and pushing pipeline * Changed branch name to master * Adding extra branch to pipeline workflow * Adding executable permission to maven wrapper * Docker build and push command config * Adding java and maven setup before mvn docker build * Changed docker repository url * Adding login to dockerhub before pushing * Create Dockerfile * Changed approach to dockerhub actions * Update Dockerfile image sha * Changed jar path to build image * [FIX] Pipeline issues * Upload artifact changed * Dockerfile target path update * Adding context to docker build&push * Add pipeline for deployment to vps * Dividing pipelines for merge and pull-request --------- Co-authored-by: Piasecki-grid <kpiasecki@griddynamics.com> Co-authored-by: Dawid Jabłoński <xederro@gmail.com> Co-authored-by: Dawid Jabłoński <50398562+xederro@users.noreply.github.com>
1 parent fc5652e commit d15b3e5

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

.github/workflows/merge.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI/CD pipeline for successful merge
2+
on:
3+
push:
4+
branches:
5+
- master
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup java
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '21'
19+
cache: 'maven'
20+
distribution: 'corretto'
21+
22+
- name: Add executable permissions
23+
run: chmod a+x mvnw
24+
25+
- name: Maven install dependencies
26+
run: ./mvnw clean install package
27+
28+
- name: Upload JAR artifact
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: app-protector
32+
path: ./target/*.jar
33+
34+
- name: Login to Docker Hub
35+
uses: docker/login-action@v3
36+
with:
37+
username: ${{ secrets.DOCKERHUB_USERNAME }}
38+
password: ${{ secrets.DOCKERHUB_TOKEN }}
39+
40+
- name: Docker Build and Push
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
push: true
45+
tags: |
46+
${{ secrets.DOCKERHUB_USERNAME }}/apiprotector:${{ github.sha }}
47+
48+
- name: Update CICD-VPS
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
git config --global user.name 'Dawid Jabłoński'
53+
git config --global user.email 'xederro@gmail.com'
54+
git config --unset-all http.https://github.com/.extraheader
55+
rm -rf .git
56+
mkdir cicd
57+
cd cicd
58+
git clone "https://x-access-token:${{ secrets.TOKEN_VPS_REPO }}@github.com/xederro/CICD-VPS.git" --depth=1
59+
cd CICD-VPS
60+
sed -i 's|piachsecki/apiprotector:[0-9a-f]\{40\}|piachsecki/apiprotector:${{ github.sha }}|g' docker-stack.yml
61+
git add .
62+
git commit -m"API Protector Update: $(date)"
63+
git push

.github/workflows/pull-request.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI/CD pipeline for successful merge
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup java
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '21'
19+
cache: 'maven'
20+
distribution: 'corretto'
21+
22+
- name: Add executable permissions
23+
run: chmod a+x mvnw
24+
25+
- name: Maven install dependencies
26+
run: ./mvnw clean install package
27+
28+
- name: Upload JAR artifact
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: app-protector
32+
path: ./target/*.jar

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM alpine/java:21-jdk@sha256:366ad7df4fafeca51290ccd7d6f046cf4bf3aa312e59bb191b4be543b39f25e2
2+
RUN mkdir /app
3+
WORKDIR /app
4+
COPY ./target/apiprotector-0.0.1-SNAPSHOT.jar /app/app-protector.jar
5+
CMD ["java", "-jar", "app-protector.jar"]

0 commit comments

Comments
 (0)