-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a dockerfile for the frontend modified second
- Loading branch information
Showing
3 changed files
with
88 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,86 @@ | ||
name: Backend CI/CD Pipeline | ||
name: Build PackIt Backend | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
- '**' | ||
tags-ignore: | ||
- 'v*' | ||
paths: | ||
- 'Packit-backend/**' | ||
- '.github/workflows/ci-cd-backend.yml' | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }}-backend | ||
|
||
jobs: | ||
build-and-test: | ||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: Packit-backend | ||
|
||
steps: | ||
# Checkout the repository code | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Clone the project | ||
uses: actions/checkout@v4 | ||
- name: Setup Java 17 (GraalVM) | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'adopt-openj9' | ||
java-version: '17' | ||
- name: Gradle build | ||
run: ./gradlew clean build | ||
|
||
# Debug step to list the contents of the repository | ||
- name: List repository contents | ||
run: ls -la | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Packit-backend | ||
path: Packit-backend/build/libs/*.jar | ||
|
||
# Debug step to list the contents of the backend directory | ||
- name: List backend directory contents | ||
run: ls -la ./packit-backend | ||
docker-build: | ||
needs: | ||
- build | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: Packit-backend | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
# Set up Node.js environment | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
steps: | ||
- name: Clone the project | ||
uses: actions/checkout@v4 | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
node-version: 'lts/*' | ||
name: Packit-backend | ||
path: Packit-backend/build/libs | ||
|
||
# Install backend dependencies | ||
- name: Install dependencies | ||
run: npm install | ||
working-directory: ./packit-backend | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Run backend tests | ||
- name: Run tests | ||
run: npm test | ||
working-directory: ./packit-backend | ||
- id: lowercase_name | ||
uses: ASzc/change-string-case-action@v6 | ||
with: | ||
string: ${{ env.IMAGE_NAME}} | ||
|
||
# Build the backend project | ||
- name: Build project | ||
run: npm run build | ||
working-directory: ./packit-backend | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ steps.lowercase_name.outputs.lowercase }} | ||
|
||
deploy: | ||
needs: build-and-test | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Checkout the repository code | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
# Log in to DockerHub using GitHub Secrets | ||
- name: Log in to DockerHub | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ github.actor }}" --password-stdin | ||
|
||
# Build and push Docker image | ||
- name: Build and push Docker image | ||
run: | | ||
docker buildx build --push --tag ${{ github.actor }}/backend-project:latest ./packit-backend | ||
- name: Build and push image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./Packit-backend | ||
push: "${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}" | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Build, deploy and docker build frontend | ||
name: Build, deploy and docker-build PackIt frontend | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
# Use the official Node.js image as the base image | ||
FROM node:20 | ||
# Use the GraalVM base image | ||
FROM ghcr.io/graalvm/graalvm-ce:22.3.2 AS builder | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy package.json and package-lock.json | ||
COPY package*.json ./ | ||
# Copy the Gradle wrapper | ||
COPY gradlew . | ||
COPY gradle gradle | ||
|
||
# Install dependencies | ||
RUN npm install | ||
# Copy the application code | ||
COPY src src | ||
COPY build.gradle . | ||
COPY settings.gradle . | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
# Build the application with Gradle | ||
RUN ./gradlew clean build | ||
|
||
# Build the application (if applicable) | ||
RUN npm run build | ||
# Use the lightweight Distroless base image | ||
FROM gcr.io/distroless/java17:nonroot | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 3000 | ||
# Copy the built JAR file from the builder stage | ||
COPY --from=builder /app/build/libs/*.jar /app/application.jar | ||
|
||
# Command to run the application | ||
CMD ["npm", "start"] | ||
# Set the entry point | ||
ENTRYPOINT ["java", "-jar", "/app/application.jar"] |