Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
ADDED: docker and CI /CD support
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Jan 16, 2024
1 parent ceccb11 commit 8311aff
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/CI-CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ci

# Trigger event on every push / delete event, no matter the branch
# on: [push, delete]

# Trigger event on every push / delete event, only in master branch
on:
push:
branches:
- "master"
delete:
branches:
- "master"

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/book-a-book-eureka:latest
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Use the UBI minimal base image for the compilation stage
FROM openjdk:17-oracle as build

# Set the working directory
WORKDIR /app

# Install necessary dependencies for compilation
RUN microdnf install --nodocs -y java-17-openjdk-headless maven && \
microdnf clean all

# Copy the source code to the container
COPY . /app

# Apply permissions
RUN chown -R 1001:1001 /app

# Set the user to run the application
USER 1001

# Compile project skipping testing goals (compilation, resources and run of tests)
RUN JAVA_HOME= ./mvnw clean package spring-boot:repackage -Dmaven.test.skip=true


# Use the UBI minimal base image for the run stage
FROM openjdk:17-oracle

# Set the working directory
WORKDIR /app

# Install necessary dependencies for running
RUN microdnf install --nodocs -y java-17-openjdk-headless && \
microdnf clean all

# Copy the directory created in the first stage into the run container
RUN mkdir -p /app/target
COPY --from=build /app/target/book-a-book-eureka.jar /app

# Cambia la propiedad del directorio '/app/target' al usuario con id 1001
RUN chown 1001:1001 /app/book-a-book-eureka.jar

# Cambia el usuario que va a ejecutar los siguientes comandos al usuario con id 1001
USER 1001

ENTRYPOINT ["java", \
"-jar", "book-a-book-eureka.jar"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# book-a-book-eureka
Stores the Eureka server for the book a book application


## One liner (build and redeploy with explicit push)
You need a token against the user in dockerhub to be able to do an explicit push
```shell
sudo docker build -t aleixmt/book-a-book-eureka:latest . && sudo docker push aleixmt/book-a-book-eureka:latest && sudo docker-compose down && sudo docker-compose up -d
```
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
version: "2.1"
services:
book-a-book-eureka:
image: aleixmt/book-a-book-eureka:latest
ports:
- "0.0.0.0:8762:8761"
restart: unless-stopped
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<groupId>net.unir.missi.desarrollowebfullstack</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<packaging>jar</packaging>
<name>eureka</name>
<description>Eureka server for the Book a book web application</description>
<properties>
Expand Down Expand Up @@ -52,6 +52,8 @@
</dependencyManagement>

<build>
<finalName>book-a-book-eureka</finalName> <!-- Final name for the WAR artifact -->

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down

0 comments on commit 8311aff

Please sign in to comment.