Skip to content

Adding first pipeline to the project #15

Adding first pipeline to the project

Adding first pipeline to the project #15

name: CI/CD pipeline for successful merge
on:
workflow_dispatch:
pull_request:
branches:
- master
- feature/github-actions
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup java
uses: actions/setup-java@v4
with:
java-version: '21'
cache: 'maven'
distribution: 'corretto'
- name: Add executable permissions
run: chmod a+x mvnw
- name: Maven install dependencies
run: ./mvnw clean install package
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: app-protector
path: ./target/*.jar
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker Build and Push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/apiprotector:${{ github.sha }}
- name: Update CICD-VPS
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name 'Dawid Jabłoński'
git config --global user.email 'xederro@gmail.com'
git config --unset-all http.https://github.com/.extraheader
rm -rf .git
mkdir cicd
cd cicd
git clone "https://x-access-token:${{ secrets.TOKEN_VPS_REPO }}@github.com/xederro/CICD-VPS.git" --depth=1
cd CICD-VPS
sed -i 's|piachsecki/apiprotector:[0-9a-f]\{40\}|piachsecki/apiprotector:${{ github.sha }}|g' docker-stack.yml
git add .
git commit -m"API Protector Update: $(date)"
git push