Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/conluz-57 #58

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
deploy/.env
deploy/postgres
deploy/influxdb

### STS ###
.apt_generated
Expand Down
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,79 @@ Alternatively, you can access the API documentation through the Swagger UI, a us
- Explore and interact with the API endpoints in a visually appealing and intuitive way.
- Swagger UI provides an easy way to understand request and response formats, and even allows you to make sample requests directly from the documentation.

## Deployment

> **Important!**
>
> Docker: Ensure that Docker is installed on your system. If not, you can download it from Docker's [official website](https://www.docker.com/get-started/).
> Docker Compose: This is a tool for defining and managing multi-container Docker applications. If you have Docker Desktop on your machine, Docker Compose should be pre-installed. If not, you can get it from [here](https://docs.docker.com/compose/install/).

### Deploy the app from the scratch

Here are the steps to deploy the app:
1. Clone the repository
```shell
git clone git@github.com:lucoenergia/conluz.git
```
2. Navigate to the deploy folder within the project directory
```shell
cd conluz/deploy
```
3. Place an `.env` file in the same directory as your `docker-compose.yml` with the following content:
```shell
CONLUZ_JWT_SECRET_KEY=your-secret-key
```
Replace your-secret-key with your actual secret key.
4. Build the Docker image
```shell
docker build -t conluz:1.0 -f Dockerfile .
```
This command builds the Docker image from the Dockerfile and tags it with the name conluz:1.0. You have to replace the version number by the one you want to deploy.
Here's what's happening in the command:
- `-t conluz:1.0` names (or "tags") the image.
- `-f deploy/Dockerfile` tells Docker where to find your Dockerfile.
- `.` tells Docker to use the current directory as the context for the build (i.e., sets the "build context").
To confirm if the Docker image has been built successfully, you can list all available Docker images with the command:
```shell
docker images
```
You should see the image (conluz:1.0) in the resulting list.
5. Start the services with Docker Compose
```shell
docker compose up -d
```
This command will start all your services in the background. Docker Compose will start all the services defined in the `docker-compose.yml` file, in the correct order.

At this point, the application should be running at http://localhost:8080.

To stop the application, you can `run docker stop conluz`.

To delete the application container, you can run `docker rm conluz`.

### Re-deploy a new version of the app

1. Stop the currently running Docker container.

You can do this with the `docker stop <container_id> command`. <container_id> is the id of your currently running Docker container.

2. Remove the stopped Docker container

This isn't strictly necessary if you're using anonymous/non-persistent volumes, but it's a good practice nonetheless to clean up after yourself. You can use the `docker rm <container_id>` command to remove the stopped container.

3. Build a new Docker image with the version of the app you want to deploy

This can be done using the `docker build` command. Make sure to tag your image with a new version tag, something like:
```shell
docker build -t conluz:2.0 -f deploy/Dockerfile .
```
4. Run a new Docker container with the new image

This can be done running this command:

```shell
docker compose up conluz -d
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first
Expand Down
11 changes: 11 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This base image contains OpenJDK 17 on Alpine Linux which is a lightweight Linux distribution.
FROM openjdk:17-jdk-alpine

# Tries to find a .jar file from within the build/libs directory from the current path.
ARG JAR_FILE=../build/libs/*.jar
# Copy the jar file to the container image.
COPY ${JAR_FILE} conluz.jar

# Run the application using the java -jar command.
# This sets conluz as default application, which Docker will execute when a container is launched from the image.
ENTRYPOINT ["java", "-jar", "/conluz.jar"]
22 changes: 21 additions & 1 deletion deploy/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ services:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=blank
volumes:
- ../../conluz-backup/postgres:/var/lib/postgresql/data # Get a backup locally
- ./postgres/data:/var/lib/postgresql/data # Get a backup locally
- ./conluz-postgres-init.sh:/docker-entrypoint-initdb.d/conluz-postgres-init.sh # Mount the init.sql script
restart: always
influxdb:
image: influxdb:1.8
ports:
- "8086:8086"
volumes:
- ./influxdb:/var/lib/influxdb
conluz:
build: .
image: conluz:0.0.1
ports:
- "8080:8080"
# Create a .env file in the folder where this file is located and define the environment variables there.
# When run docker-compose up, Docker will automatically pick up the .env file in the same directory as this docker-compose.yml file, and substitute the values of the environment variables accordingly.
environment:
- CONLUZ_JWT_SECRET_KEY
- SPRING_DATASOURCE_URL
- SPRING_INFLUXDB_URL
depends_on:
- postgres
- influxdb
Loading