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

Release/candidate #187

Merged
merged 34 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
169ccfb
Update readme.md
MartinLupa May 10, 2024
534c885
Added a 'tests' workflow
Mathias-Gleitze May 20, 2024
b626313
Trigger build
Mathias-Gleitze May 20, 2024
148bbac
Test tests
Mathias-Gleitze May 20, 2024
5fff26e
Trigger build
Mathias-Gleitze May 20, 2024
a681601
Install pytest
Mathias-Gleitze May 20, 2024
f115eb9
Added requirement 'requests'
Mathias-Gleitze May 20, 2024
db01add
Check if application is up
Mathias-Gleitze May 20, 2024
df129d4
Check docker logs
Mathias-Gleitze May 20, 2024
f50aef4
Test access
Mathias-Gleitze May 20, 2024
3ba6bb0
Attempt using service.
Mathias-Gleitze May 20, 2024
85ae67a
Another test
Mathias-Gleitze May 20, 2024
bfcda24
Merge pull request #175 from DevopsGroupC/feature/174-fix-unit-tests-…
Mathias-Gleitze May 20, 2024
a06f6af
Changed database behavior
Mathias-Gleitze May 20, 2024
a3ef062
Changed workflows back to normal workflow
Mathias-Gleitze May 20, 2024
caf5a98
Removed unused files and nuget packages
Mathias-Gleitze May 20, 2024
ab83845
Merge pull request #176 from DevopsGroupC/feature/174-fix-unit-tests-…
Mathias-Gleitze May 20, 2024
6a65385
Merge pull request #177 from DevopsGroupC/feature/172-cleanup-unused-…
Mathias-Gleitze May 20, 2024
3ee6152
added secrets to .gitignore
Mathias-Gleitze May 22, 2024
a4ed742
Merge pull request #179 from DevopsGroupC/feature/178-automate-report…
Mathias-Gleitze May 22, 2024
189bf25
Update submodule reference to latest commit
invalid-email-address May 22, 2024
97478d1
Merge pull request #180 from DevopsGroupC/update-report-pdf
aswesty May 22, 2024
923c674
Update submodule reference to latest commit
invalid-email-address May 22, 2024
82d4a62
Merge pull request #181 from DevopsGroupC/update-report-pdf
aswesty May 22, 2024
134a84e
Removed vagrant related files
Mathias-Gleitze May 23, 2024
10eddc9
Merge pull request #183 from DevopsGroupC/182-remove-vagranttxt
Mathias-Gleitze May 23, 2024
8b2d87e
Updated README.md to reflect the current state of the system
Mathias-Gleitze May 23, 2024
a640bde
Merge pull request #185 from DevopsGroupC/184-update-readmemd
Mathias-Gleitze May 23, 2024
6a6ff1d
Update report.yml
Mathias-Gleitze May 23, 2024
acfd225
Update report.yml
Mathias-Gleitze May 23, 2024
ecc915f
Update report.yml
Mathias-Gleitze May 23, 2024
5fc3d7a
Update report.yml
Mathias-Gleitze May 23, 2024
dfe9d2f
Update submodule reference to latest commit
invalid-email-address May 23, 2024
f6f6c7b
Merge pull request #186 from DevopsGroupC/update-report-pdf
Mathias-Gleitze May 23, 2024
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
86 changes: 86 additions & 0 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Build Report

on:
workflow_dispatch:

permissions:
contents: write

jobs:
build_latex:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
ssh-key: ${{ secrets.DEPLOY_KEY_FOR_REPORT_PRIVATE }}

- name: Update submodules
run: |
git submodule update --init --recursive --remote

- name: Set up LaTeX
uses: xu-cheng/latex-action@v3
with:
working_directory: report
root_file: main.tex

- name: Move main.pdf
run: |
cd report
mv -f main.pdf ./build

- name: Setup SSH for pushing to report repository
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY_FOR_REPORT_PRIVATE }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts

- name: Commit and push main.pdf
run: |
cd report

git config user.name "github-actions"
git config user.email "[email protected]"

echo "git status:"
git status

git checkout main
git pull origin main

echo "git status after pull:"
git status

git add build/main.pdf
git commit -m "Update report PDF"

echo "git status after adding commit with new pdf:"
git status

git remote set-url origin [email protected]:DevopsGroupC/report.git
GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' git push -f origin main

- name: Setup SSH for pushing to main repository
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY_FOR_MINITWIT_PRIVATE }}" > ~/.ssh/id_minitwit_rsa
chmod 600 ~/.ssh/id_minitwit_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts

- name: Update submodule reference and push
run: |
git config user.name "github-actions"
git config user.email "[email protected]"

git fetch origin
git reset --hard origin/develop

git submodule update --remote

git checkout -b update-report-pdf
git add report
git commit -m "Update submodule reference to latest commit"
GIT_SSH_COMMAND='ssh -i ~/.ssh/id_minitwit_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' git push -f --set-upstream origin update-report-pdf
60 changes: 60 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run Tests
# on:
# workflow_run:
# workflows: ["Format Check"]
# types:
# - completed
on:
pull_request:
types: [opened, reopened, edited, synchronize, ready_for_review]

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Wait for docker
run:
sleep 5

- name: Build Docker image
run: docker build -t csharp-minitwit:latest ./csharp-minitwit

- name: Run Docker container
run: |
docker run -d --name csharp-minitwit -p 5000:8080 csharp-minitwit:latest

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Python dependencies
run: |
cd ./csharp-minitwit/Tests
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Check Docker Logs
run: docker logs csharp-minitwit

- name: Check Public Endpoint
run: |
status_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/public)
if [ "$status_code" -ne 200 ]; then
echo "Error: $status_code"
exit 1
fi

- name: Run Python tests
run: |
cd ./csharp-minitwit/Tests
pytest minitwit_sim_api_test.py
pytest refactored_minitwit_tests.py

- name: Clean up
run: |
docker stop csharp-minitwit
docker rm csharp-minitwit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ __pycache__/
.vagrant
.Python
build/
!report/build/
develop-eggs/
dist/
downloads/
Expand Down Expand Up @@ -637,3 +638,4 @@ infrastructure/.terraform/*
infrastructure/temp/*
infrastructure/.terraform*
infrastructure/grafana/ca_cert
infrastructure/secrets
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "report"]
path = report
url = https://github.com/DevopsGroupC/report
121 changes: 45 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,96 +10,64 @@
<li>
<a href="#about-the-project">About The Project</a>
<ul>
<li><a href="#built-with">Built With</a></li>
<li><a href="#the-application">The application</a></li>
<li><a href="#prerequisites">Prerequisites</a></li>
</ul>
</li>
<li>
<a href="#usage">Running the project</a>
<a href="#running-the-project">Running the project</a>
<ul>
<li><a href="#itu-minitwit">itu-minitwit</a></li>
<ul>
<li><a href="#itu-minitwit-tests">Tests</a></li>
</ul>
<li><a href="#csharp-minitwit">csharp-minitwit</a></li>
<ul>
<li><a href="#csharp-minitwit-tests">Tests</a></li>
</ul>
<li><a href="#run-using-docker-the-prefered-method">Using docker (the prefered method)</a></li>
<li><a href="#run-using-the-dotnet-runtime-directly">Using the dotnet runtime directly</a></li>
<li><a href="#monitoring">Monitoring</a></li>
<li><a href="#testing">Testing</a></li>
</ul>
</li>
<li><a href="#Acknowledgments">Acknowledgments</a></li>
<li><a href="#how-to-contribute">How to contribute</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
</ol>
</details>

## About The Project
This project is part of the course [DevOps, Software Evolution and Software Maintenance, MSc (Spring 2024)](https://learnit.itu.dk/local/coursebase/view.php?ciid=1391)

The project currently consists of two folders:
- **itu-minitwit**, which is a small Twitter copy made in Python.
The project currently consists of three main folders:
- **csharp-minitwit**, which is a ported version of itu-minitwit, made in C#.
- **infrastructure**, Containing shell and Terraform scripts for provisioning.
- **report**, Containing a report written in LaTex, generated as a pdf in the build folder.

### Built With
- .Net 8
- ASP.NET
- SQLite

### Prerequisites
* A modern Python, i.e., version >= 3.10,
- There are various ways of installing it, either via the system's package manager (`apt search python3`)
- manually from [python.org](https://www.python.org/downloads/)
- via [pyenv](https://github.com/pyenv/pyenv)
- via [Anaconda](https://www.anaconda.com/products/individual)
* The Python dependencies from `itu-minitwit`:
- [Flask](https://flask.palletsprojects.com/en/3.0.x/) >= version 3.0.0
- [Werkzeug](https://palletsprojects.com/p/werkzeug/) >= version 3.0.0
- [Jinja2](https://palletsprojects.com/p/jinja/) >= version 3.0.0
* A current C compiler, e.g., `gcc`
- Likely it is already part of your Linux installation.
- You can check that, for example with:
```bash
gcc --version
```
- Since the `flag_tool` is a C program, you have to compile it again:
* `flag_tool` includes `sqlite3.h`, which is likely not yet installed on your system.
* It can be installed (together with the required shared library) via:
```bash
sudo apt install libsqlite3-dev
```
* To work with the database, you likely need [`sqlite3`](https://sqlite.org/index.html) ((`apt search sqlite3`))
- To inspect the database file while refactoring, you might want to use a tool to "look into" your database file, such as the [DB Browser for SQLite](https://sqlitebrowser.org/), which you can install via:
```bash
sudo apt install sqlitebrowser
```
### The application
The 'csharp-minitwit' application is a miniature version of X (formerly known as Twitter).

### Prerequisites
* Linux. It is also possible to work on the project using MacOS, Windows has a few Git issues with the 'infrastructure/secrets:Zone.Identifier' file.
* The [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0). There are multiple options for downloading depending on your operating system. If on linux, we recommend the [scripted install](https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install).
* SQLite, multiple guides can be found online on how to install, this highly depends on which operating system is used.
* [Docker](https://docs.docker.com/engine/install/)
* Python with the pytest and request pip-packages installed (only needed for testing).

<!-- USAGE EXAMPLES -->
## Usage
## Running the project
This project can be run in two ways:

### itu-minitwit
This project can be run using a terminal.
cd into the correct folder:
```sh
cd itu-minitwit
```
Run using `Python`:
### Run using docker (the prefered method):
Run using `docker` - runs only the app:
```sh
python minitwit.py
docker build -t csharp-minitwit .
docker run -p 5000:8080 csharp-minitwit
```
At this point, the application can be accessed using the link provided in the terminal (http://localhost:5000).

#### itu-minitwit tests
Tests for `itu-minitwit` can be run by opening a new terminal and cd into correct folder:
```sh
cd itu-minitwit
```
And running the tests using `Pytest`:
Run using `docker-compose` - runs multiple development services, such as Prometheus, Grafana, etc.:
```sh
pytest minitwit_tests.py
docker-compose up
```
At this point, the application can be accessed using the link provided in the terminal (http://127.0.0.1:5000).

### csharp-minitwit
This project can be run using a terminal.
### Run using the dotnet runtime directly:
This firstly requires a few changes to the code. The default connection string points to a folder which will be generated in the docker container normally.
Change the connection string in 'appsettings.Development.json', from 'Data Source=/app/Databases/volume/minitwit.db' to 'Data Source=./Databases/volume/minitwit.db' ***DO NOT COMMIT THIS***.

cd into the correct folder:
```sh
cd csharp-minitwit
Expand All @@ -108,17 +76,8 @@ Run using `dotnet`:
```sh
dotnet run
```
Run using `docker` - runs only the app:
```sh
docker build -t csharp-minitwit .
docker run -p 5000:8080 csharp-minitwit
```
At this point, the application can be accessed using the link provided in the terminal (http://localhost:5000). Furthermore, API documentation can be accessed at http://localhost:5000/swagger.

Run using `docker-compose` - runs multiple development services, such as Prometheus, Grafana, etc.:
```sh
docker-compose up
```


### Monitoring
| Service | Endpoint |
Expand All @@ -128,16 +87,26 @@ docker-compose up
| Grafana | http://localhost:3000 |


#### csharp-minitwit tests
Tests for `csharp-minitwit` can be run by opening a new terminal and cd into the test folder:
### Testing
When developing APIs locally, Swagger is setup at http://localhost:5000/swagger/index.html for easy manual testing.

Unit tests for `csharp-minitwit` can be run by opening a new terminal and cd into the test folder:
```sh
cd csharp-minitwit/Tests
```
And running the tests using Pytest:
```sh
pytest refactored_minitwit_tests.py
pytest minitwit_sim_api_test.py
```

## How to contribute
For this repository we try to follow the [GitFlow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) workflow:
* Create an issue
* Create a branch using the GitHub issue tracker to ensure correct naming (remember to prefix the branch name with feature/{issue_name})
* Develop feature
* Create a pull request

<!-- ACKNOWLEDGMENTS -->
## Acknowledgments
Shout out to Chatgpt for help with debugging.
Shout out to [ChatGPT](https://chatgpt.com/) for help with debugging.
Binary file removed csharp-minitwit/Databases/volume/minitwit.db
Binary file not shown.
1 change: 0 additions & 1 deletion csharp-minitwit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ENV ASPNETCORE_ENVIRONMENT=${ENVIRONMENT}

COPY --from=build /app/out .
COPY ./Databases/schema.sql ./schema.sql
COPY ./Databases/volume/minitwit.db ./Databases/volume/minitwit.db
COPY ./Services/latest_processed_sim_action_id.txt ./Services/latest_processed_sim_action_id.txt
EXPOSE 5000

Expand Down
13 changes: 13 additions & 0 deletions csharp-minitwit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@

if (builder.Environment.IsDevelopment())
{
string filePath = connectionString!.Split('=')[1];
string? directoryPath = Path.GetDirectoryName(filePath);

if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);

Check warning on line 52 in csharp-minitwit/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet-format

Possible null reference argument for parameter 'path' in 'DirectoryInfo Directory.CreateDirectory(string path)'.

Check warning on line 52 in csharp-minitwit/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet-format

Possible null reference argument for parameter 'path' in 'DirectoryInfo Directory.CreateDirectory(string path)'.
}

if (!File.Exists(filePath))
{
File.Create(filePath).Close();
}

builder.Services.AddDbContext<MinitwitContext>(options =>
options.UseSqlite(connectionString));
}
Expand Down
2 changes: 2 additions & 0 deletions csharp-minitwit/Tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
requests
5 changes: 4 additions & 1 deletion csharp-minitwit/csharp-minitwit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.7.0-rc.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" />
<PackageReference Include="Scriban" Version="5.9.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -34,4 +33,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Databases\volume\" />
</ItemGroup>

</Project>
Loading
Loading