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

Commit

Permalink
ADDED: docker support and ci cd
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Jan 16, 2024
1 parent aa6396b commit 518f578
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.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-operador:latest
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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-operador.jar /app

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

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

# Set the application profile in order to change the config of DB location
ENV spring_profiles_active=prod

ENTRYPOINT ["java", \
"-jar", "book-a-book-operador.jar"]
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
version: "2.1"
services:
book-a-book-buscador:
image: aleixmt/book-a-book-buscador:latest
ports:
- "0.0.0.0:8082:8081"
#restart: unless-stopped

book-a-book-operador:
image: aleixmt/book-a-book-operador:latest
ports:
- "0.0.0.0:8084:8083"
#restart: unless-stopped

postgres_db:
image: postgres
environment:
- PUID=1001
- PGID=1001
- TZ=Etc/UTC
- POSTGRES_PASSWORD=chemistry
- POSTGRES_USER=aleixmt
- POSTGRES_DB=book-a-book-operador
ports:
- "0.0.0.0:5433:5432"
restart: unless-stopped
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<groupId>net.unir.missi.desarrollowebfullstack.bookabook</groupId>
<artifactId>operador</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>operador</name>
<description>Operador microservice for the Book a book web application</description>
<properties>
Expand Down Expand Up @@ -42,6 +43,8 @@
</dependencies>

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

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
####################################
### SETTING UP CONNECTION TO DB ####
####################################

# Set connection to the desired table of DB using URL
spring.datasource.url=jdbc:postgresql://localhost:5432/bookabook

# Database credentials
spring.datasource.username=aleixmt
spring.datasource.password=chemistry

# Default policy with database contents when booting: "validate" checks consistency, "create" wipes colliding tables and creates
# them from scratch, "create-drop" creates DB schema and then drops the information. "Update" updates the information.
# "None" does nothing
spring.jpa.hibernate.ddl-auto=update

# Output the SQL queries
spring.jpa.show-sql=true
# Format of the SQL queries written in the output
spring.jpa.properties.hibernate.format_sql=true

21 changes: 21 additions & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
####################################
### SETTING UP CONNECTION TO DB ####
####################################

# Set connection to the desired table of DB using URL
spring.datasource.url=jdbc:postgresql://postgres_db:5432/book-a-book-operador

# Database credentials
spring.datasource.username=aleixmt
spring.datasource.password=chemistry

# Default policy with database contents when booting: "validate" checks consistency, "create" wipes colliding tables and creates
# them from scratch, "create-drop" creates DB schema and then drops the information. "Update" updates the information.
# "None" does nothing
spring.jpa.hibernate.ddl-auto=update

# Output the SQL queries
spring.jpa.show-sql=true
# Format of the SQL queries written in the output
spring.jpa.properties.hibernate.format_sql=true

0 comments on commit 518f578

Please sign in to comment.