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

feat(iac): create k8s workspace #38

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e687eef
chore: execute order 66
gm112 Dec 12, 2024
cd356b0
feat(iac): add k8s project
gm112 Dec 29, 2024
0c113ab
chore: bump postgres image
gm112 Dec 29, 2024
775e107
fix(scripts): change ID constraints to better way
gm112 Jan 6, 2025
8813998
refactor: simplify k8s project
gm112 Jan 12, 2025
a54d6ee
chore: oops include kustomization
gm112 Jan 12, 2025
5e2b14f
fix: apply generators from overlay
gm112 Jan 13, 2025
8fcb907
fix(docker): utilize docker cache faster for epic wins
gm112 Jan 13, 2025
6a054a1
feat: add scripts for minikube checks and project directory validation
gm112 Jan 15, 2025
fd80023
feat: add destroy command
gm112 Jan 15, 2025
ffa3f4b
chore: update gitattributes
gm112 Jan 15, 2025
d25aacb
chore: apply shellcheck fixes
gm112 Jan 15, 2025
b784979
feat: add setup script for dev environments
gm112 Jan 15, 2025
f29ce7f
fix: make dev setup scripts consistent
gm112 Jan 15, 2025
39fed51
feat: enhance apply.sh with env variable loading and improve kustomiz…
gm112 Jan 15, 2025
4ee8506
chore: cleanup repo
gm112 Jan 15, 2025
c385f20
feat(api): update generatorConfig to use vars
gm112 Jan 17, 2025
3145b10
chore: add mg-config-zero
gm112 Jan 17, 2025
f48f1b8
chore: move mg-zero-xml
gm112 Jan 17, 2025
ed54a3d
chore: 8=====D
gm112 Jan 17, 2025
5eee773
chore: update README
gm112 Jan 17, 2025
ef96b16
chore: apply mg-stuffs
gm112 Jan 17, 2025
943d37d
chore: fix mybatis
gm112 Jan 17, 2025
88aac41
chore: update documentation for iac workspace
gm112 Jan 17, 2025
054ad7e
docs(iac): document convention of the kube project
gm112 Jan 17, 2025
4792f67
chore: tweak docs wording a bit
gm112 Jan 17, 2025
a7c8d0b
docs(iac): oops i forgot to complete a sentence
gm112 Jan 17, 2025
d7fc111
docs(iac): clean up convention
gm112 Jan 17, 2025
9a63a28
chore: brb going to render html with my ass
gm112 Jan 18, 2025
22a3341
feat(iac): add production configuration for pizza time
gm112 Jan 18, 2025
11b4a51
feat(iac): add initial kube manifest for gh action
gm112 Feb 6, 2025
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
15 changes: 15 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
POSTGRES_DB=zfgc_dev
POSTGRES_USER=postgres
POSTGRES_PASSWORD=123456

SPRING_DATASOURCE_USERNAME=postgres
SPRING_DATASOURCE_PASSWORD=123456
MBG_JBDC_USERNAME=postgres
MBG_JDBC_PASSWORD=123456

PGADMIN_DATABASE_URI=postgres://postgres:123456@zfgbb_postgresql:5432/zfgc_dev
SPRING_DATASOURCE_URL=jdbc:postgresql://zfgbb_postgresql:5432/zfgc_dev
MBG_JDBC_URL=jdbc:postgresql://zfgbb_postgresql:5432/zfgc_dev

ZFGBB_CONTENT_PATH=/usr/local/tomcat/webapps/content
ZFGBB_CONTENT_IMAGES=/usr/local/tomcat/webapps/content/images
11 changes: 11 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ZFGBB_DATABASE=zfgc_dev
ZFGBB_USER=zfgbb_user
ZFGBB_USER_PASSWORD=123456

SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/zfgc_dev
SPRING_DATASOURCE_USERNAME=zfgbb_user
SPRING_DATASOURCE_PASSWORD=123456

MBG_JDBC_URL=jdbc:postgresql://localhost:5432/zfgc_dev
MBG_JBDC_USERNAME=zfgbb_user
MBG_JDBC_PASSWORD=123456
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
22 changes: 11 additions & 11 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
38 changes: 19 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: CI
on:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [17]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version}} for x64
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
architecture: x64
cache: maven
- name: Build with Maven
name: CI
on:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [17]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version}} for x64
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
architecture: x64
cache: maven
- name: Build with Maven
run: mvn clean compile package -Dmaven.test.skip=true
31 changes: 31 additions & 0 deletions .github/workflows/k8s-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# name: Kubernetes Deployment

# on:
# push:
# branches:
# - main

# jobs:
# deploy:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: Set up Kubernetes CLI
# uses: azure/setup-kubectl@v1
# with:
# version: 'v1.21.0'
# - name: Create MySQL and PostgreSQL Secrets
# run: |
# echo "$MYSQL_PASSWORD" | base64 | kubectl create secret generic mysql-secret \
# --from-literal=password=- \
# --dry-run=client -o yaml | kubectl apply -f -
# echo "$POSTGRES_PASSWORD" | base64 | kubectl create secret generic postgres-secret \
# --from-literal=password=- \
# --dry-run=client -o yaml | kubectl apply -f -
# env:
# MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
# POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
# - name: Deploy
# run: |
# export $(cat kustomize.env | xargs) # Load and export env vars
# kustomize build base | kubectl apply -f -
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
### Build Files ###
dist/

### Environment Files ###
**/.env
**/.env.secret
*.env
*.env.secret
!.env.docker
!.env.local
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"vscjava.vscode-java-pack",
"vmware.vscode-boot-dev-pack"
]
}
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug Backend",
"request": "launch",
"mainClass": "com.zfgc.zfgbb.ZfgbbApplication",
"projectName": "zfgbb",
"envFile": "${workspaceFolder}/.env.local",
"env": {
"ZFGBB_CONTENT_PATH": "${workspaceFolder}/backend-assets",
"ZFGBB_CONTENT_IMAGES": "${workspaceFolder}/backend-assets"
}
},
{
"type": "java",
"name": "Debug Backend (docker)",
"request": "launch",
"mainClass": "com.zfgc.zfgbb.ZfgbbApplication",
"projectName": "zfgbb",
"envFile": "${workspaceFolder}/.env.docker"
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "interactive",
"java.compile.nullAnalysis.mode": "automatic"
}
52 changes: 32 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
FROM maven:3.9-eclipse-temurin-17 AS build

RUN mkdir -p /usr/src/zfgcbb
COPY . /usr/src/zfgcbb

WORKDIR /usr/src/zfgcbb

RUN mvn clean compile package -Dmaven.test.skip=true

FROM postgres:16 AS database

#RUN echo "CREATE DATABASE zfgcbb; CREATE USER $SPRING_DATASOURCE_USERNAME; GRANT ALL PRIVILEGES ON DATABASE zfgcbb TO $SPRING_DATASOURCE_USERNAME;" > /docker-entrypoint-initdb.d/init.sql

FROM tomcat:jre17-temurin-jammy AS deploy

COPY --from=build /usr/src/zfgcbb/target/*.war /usr/local/tomcat/webapps/

EXPOSE 8080

CMD ["catalina.sh", "run"]
# FROM maven:3.9-eclipse-temurin-17 AS base

# WORKDIR /usr/src
# ADD ./mvn* ./
# ADD ./pom.xml ./
# RUN mvn install -Dmaven.test.skip=true

# # Yeah, this is ugly. Sue me.
# CMD ["mvn", "install", "-Dmaven.test.skip=true"]

FROM maven:3.9-eclipse-temurin-17 AS build
WORKDIR /usr/src
ADD ./mvn* ./
ADD ./pom.xml ./
# RUN mvn install -Dmaven.test.skip=true

ADD ./src ./src
RUN mvn clean compile package -Dmaven.test.skip=true

# FIXME: This image should be switched to gcr.io/distroless/java-base-debian12 because it is much smaller. For now, this will work.
FROM tomcat:jre17-temurin-jammy AS deploy

COPY --from=build /usr/src/target/*.war /usr/local/tomcat/webapps/
RUN mkdir -p /usr/local/tomcat/webapps/content/images

EXPOSE ${ZFGBB_BACKEND_PORT:-8080}
CMD ["catalina.sh", "run"]

FROM postgres:16 AS database
ADD ./scripts/sql/provisioning/1-zfgbb.initialize-database.sh /docker-entrypoint-initdb.d/1-zfgbb.initialize-database.sh
# We exclude .sql from the file name so that it gets ignored by the init script.
ADD ./scripts/sql/provisioning/2-provision-database.sql /docker-entrypoint-initdb.d/2-provision-database
121 changes: 119 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,119 @@
Java 17
maven clean install -Dmaven.test.skip=true
# ZFGBB Backend

Bringin back the Drama Llama from the dead!

[![CI](https://github.com/ZFGCCP/ZFGCBB/actions/workflows/ci.yml/badge.svg)](https://github.com/ZFGCCP/ZFGCBB/actions/workflows/ci.yml)

## Table of Contents

- [ZFGBB Backend](#zfgbb-backend)
- [Table of Contents](#table-of-contents)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Developing with an IDE](#developing-with-an-ide)
- [Visual Studio Code](#visual-studio-code)
- [Eclipse](#eclipse)
- [Developing Standalone](#developing-standalone)
- [Building](#building)
- [Running Tests](#running-tests)
- [Running MyBatis Generator](#running-mybatis-generator)
- [IaC (Infrastructure as Code)](#iac-infrastructure-as-code)
- [License](#license)

## Getting Started

### Prerequisites

- [Git Bash](https://git-scm.com/downloads)
- [Docker/Docker-Compose](https://docs.docker.com/get-docker/)
- [Java 17](https://www.oracle.com/java/technologies/downloads/)
- [Maven](https://maven.apache.org/)
- If running locally
- [PostgreSQL](https://www.postgresql.org/download/)
- [Tomcat](https://tomcat.apache.org/)

#### Setup

To use the automatic setup script to download and install dependencies, make sure [Git Bash](https://git-scm.com/downloads) is installed. This script currently supports Windows, macOS, and Linux.

This repository provides a [setup script](./scripts/development/setup.sh). It will automatically detect your environment and prompt you to install dependencies. For Linux, only two kinds of distros are handled for installing packages (Arch and Ubuntu). For any other Linux distro, the script will just check the presence of dependencies.

Using the script can be done by invoking the following command.

```bash
./scripts/development/setup.sh
```

### Developing with an IDE

Opening the project in Eclipse or Visual Studio Code is recommended.

Stand up the database using the following command.

```bash
docker-compose up -d postgresql pgadmin
```

You can access pgadmin at `http://0.0.0.0:5050`.

#### Visual Studio Code

The [vscode settings](./.vscode/settings.json) provides a basic setup for developing with VS Code.

The following build actions are available:

- `Debug Backend`: Runs the backend in debug mode, using `.env.local` as the environment file. NOTE: Docker should resolve just fine, but if not you can use the (Docker) variant of this action.
- `Debug Backend (Docker)`: Runs the backend in debug mode, using `.env.docker` as the environment file.

#### Eclipse

Eclipse will respect the applications.properties file, so you can use that to configure the application.

### Developing Standalone

To run the application in development mode, run the following command:

```bash
mvn clean run package -Dmaven.test.skip=true
```

This will start the application in development mode, and you can access it at `http://0.0.0.0:8080`.

### Building

To build the application, run the following command:

```bash
mvn clean compile package -Dmaven.test.skip=true
```

This will create a `.war` file in the `target` directory.

### Running Tests

To run the tests, run the following command:

```bash
mvn test
```

This will run all the tests in the [src/test](src/test) directory.

### Running MyBatis Generator

To run the MyBatis generator, run the following command:

```bash
nvm mybatis-generator:generate
```

This will generate the MyBatis mappers and Java models based on the database schema.

## IaC (Infrastructure as Code)

We implement a [Kubernetes Project](./iac/) to deploy the application to a Kubernetes cluster. This also contains configuration for the legacy zfgc.com environment under the `old-skool` service. More details can be found in the [IaC README](./iac/).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Loading
Loading