Skip to content

Commit 7f0cb51

Browse files
committed
feature: automatizacion de deploy
1 parent 3009808 commit 7f0cb51

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Push Backend Image
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
- "dev"
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Log in to the Container registry
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ghcr.io
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Extract metadata (tags, labels) for Docker
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
images: ghcr.io/YOUR_GITHUB_USERNAME/backend-tpi # Reemplaza con tu usuario y nombre de imagen
32+
33+
- name: Build and push Docker image
34+
uses: docker/build-push-action@v5
35+
with:
36+
context: .
37+
push: true
38+
tags: ${{ steps.meta.outputs.tags }}
39+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
FROM amazoncorretto:17-alpine-jdk
1+
# Stage 1: Build the application
2+
FROM maven:3.8.5-openjdk-17 AS builder
3+
WORKDIR /app
4+
COPY pom.xml .
5+
COPY .mvn .mvn
6+
RUN mvn dependency:go-offline
7+
COPY src src
8+
RUN mvn package -DskipTests
29

3-
COPY target/project-0.0.1-SNAPSHOT.jar /api-v1.jar
4-
5-
ENTRYPOINT ["java", "-jar", "/api-v1.jar"]
10+
# Stage 2: Create the final lightweight image
11+
FROM openjdk:17-jdk-slim
12+
WORKDIR /app
13+
COPY --from=builder /app/target/*.jar app.jar
14+
EXPOSE 8080
15+
ENTRYPOINT ["java","-jar","app.jar"]

0 commit comments

Comments
 (0)