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

Add initial CI/CD workflow #5

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Merseleo
Copy link
Contributor

@Merseleo Merseleo commented Feb 25, 2025

Closes #3

What I have made

  • added a basic CI/CD pipeline to the mock backend, including jobs for
    • building the mock backend
    • linting the mock backend (In order for this job to run successfully, the code had to be formatted beforehand)
    • building and publishing a docker image of the mock backend to GitHub registry
    • deploying the mock backend on the snowballr server
  • re-initialize docker for the mock backend (using docker init) for best practices
  • small improvements in the eslint and prettier configuration

@Merseleo Merseleo linked an issue Feb 25, 2025 that may be closed by this pull request
@Merseleo Merseleo self-assigned this Feb 25, 2025
@Merseleo Merseleo removed the request for review from Slartibartfass2 February 25, 2025 13:58
@Merseleo Merseleo marked this pull request as draft February 25, 2025 13:58
@Merseleo Merseleo force-pushed the ci/3-add-initial-ci-cd-workflow branch 6 times, most recently from b2f988c to a39d677 Compare February 26, 2025 10:39
@Merseleo Merseleo force-pushed the ci/3-add-initial-ci-cd-workflow branch from 1c7d284 to 4a3b87e Compare March 6, 2025 09:22
@Merseleo Merseleo marked this pull request as ready for review March 6, 2025 09:23
@Merseleo Merseleo force-pushed the ci/3-add-initial-ci-cd-workflow branch 7 times, most recently from 39c03f5 to 3237bef Compare March 6, 2025 12:02
@Merseleo Merseleo force-pushed the ci/3-add-initial-ci-cd-workflow branch from 3237bef to 380fba3 Compare March 6, 2025 12:06
@Merseleo
Copy link
Contributor Author

Merseleo commented Mar 6, 2025

Probably we need to find another solution for the deployment, because if we regularly start new mock backends on the server without stopping and deleting the existing containers, we will run into space problems very quickly. I am open for suggestions.

.dockerignore Outdated
Comment on lines 23 to 25
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we just remove them in the last pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are, as I said I generated this file and docker seems to be the opinion that these files should not be included, but as I said, I would integrate it. I will delete it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me like there is a lot in here that is not part of our project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, there is a lot of stuff not included in our project. I didnt create this .dockerignore on my own, but (as I wrote in the PR description) used docker init as @Slartibartfass2 suggested. This command generated this file and the compose file and Dockerfile etc. based on our files and additional best practices. So imo it is no problem, that this file ignore more files per default than we have, because if we add files later it is more unlikely that we get problems because someone (probably me) forgot to add the files to this .dockerignore

compose.yaml Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why go for a compose file if we're only working with one container?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I didn't create this compose file, it was completely generated by docker init
  2. Imo, we should not delete it either, because it seems to me that on the one hand it is easier to start a container with a compose file and on the other hand it is not impossible that another container could come later or something and then you can simply extend it directly.

Basically, I understand that it seems pointless, but to be honest, I don't think this file needs to be maintained and therefore doesn't mean any effort, does it?

@@ -1,7 +1,7 @@
{
"name": "snowballr-mock-backend",
"version": "1.0.0",
"description": "A Mock Backend for the SnowballR Frontend Development",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is title-case a no-go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not a no-go, in my experience it's just very unusual for descriptions, especially of packages. But if you want to go with this title-case I can change it back, but the version should stay 0.1, as everything can still change in the mock backend (e.g. dynamically load data at the start will be introduced soon).

Comment on lines -20 to +19
export const LOGGING_INTERCEPTOR: ServerInterceptor = function (
methodDescriptor: ServerMethodDefinition<any, any>,
export const LOGGING_INTERCEPTOR: ServerInterceptor = function <RequestT, ResponseT>(
methodDescriptor: ServerMethodDefinition<RequestT, ResponseT>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting choice. I am surprised it works, I didn't know you could just do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched for a solution of this problem of types for generic functions and the first solution was using Generics. Didnt know this either, but it works and seems a bit more elegant to. Or should I change it back and add a comment for the linter?

Dockerfile Outdated

################################################################################
# Create a stage for installing production dependecies.
FROM base as deps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker warns about inconsistent casing of keywords. as should probably be capitalized everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I corrected it.

Comment on lines +20 to +21
with:
submodules: "recursive"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we explicitly want to pull all submodules for linting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we dont need to, but I pull the submodule to use the custom "setup" workflow (with always generate the grpc stuff and therefore need the submodule). If it is in your opinion not good practice, I can delete it and dont use the "setup" workflow.


docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

docker run -d --name snowballr-mock-backend -p 3001:3001 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on exposing both viable ports? (the grpc-web one and the native one)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first thought was, that it is not necessary, as this is the deployed mock backend and why should we use grpcui or grpcurl with this, but on the other hand, it shouldn't cause any problem to expose the other port, so I will add it.

mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "StrictHostKeyChecking no" >> ~/.ssh/config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already part of the ssh command below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is, you are right (I must admit, I only copied this code and forgot to check, whether there are duplicate "lines"). I delete this line.

Comment on lines 48 to 50
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the missing push: true intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, i accidentally deleted this line.

@luca-schlecker
Copy link
Collaborator

Probably we need to find another solution for the deployment, because if we regularly start new mock backends on the server without stopping and deleting the existing containers, we will run into space problems very quickly. I am open for suggestions.

Couldn't we use the latest tag and update the existing container instead of pulling a new specific version?

@Merseleo Merseleo removed the request for review from Slartibartfass2 March 7, 2025 09:07
…rnings in Dockerfile and delete Dockerfile and compose file from .dockerignore)
@Merseleo Merseleo force-pushed the ci/3-add-initial-ci-cd-workflow branch from 4b7a7e2 to b134277 Compare March 7, 2025 09:42
@Merseleo Merseleo force-pushed the ci/3-add-initial-ci-cd-workflow branch from b134277 to fbc2257 Compare March 7, 2025 09:45
Copy link
Contributor Author

@Merseleo Merseleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick response. I guess you also didn't test the deploy workflow. Any ideas how we can properly test it or do you think it will work without any problems or we will see the errors when merging to main?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, there is a lot of stuff not included in our project. I didnt create this .dockerignore on my own, but (as I wrote in the PR description) used docker init as @Slartibartfass2 suggested. This command generated this file and the compose file and Dockerfile etc. based on our files and additional best practices. So imo it is no problem, that this file ignore more files per default than we have, because if we add files later it is more unlikely that we get problems because someone (probably me) forgot to add the files to this .dockerignore

.dockerignore Outdated
Comment on lines 23 to 25
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are, as I said I generated this file and docker seems to be the opinion that these files should not be included, but as I said, I would integrate it. I will delete it.

Dockerfile Outdated

################################################################################
# Create a stage for installing production dependecies.
FROM base as deps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I corrected it.

compose.yaml Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I didn't create this compose file, it was completely generated by docker init
  2. Imo, we should not delete it either, because it seems to me that on the one hand it is easier to start a container with a compose file and on the other hand it is not impossible that another container could come later or something and then you can simply extend it directly.

Basically, I understand that it seems pointless, but to be honest, I don't think this file needs to be maintained and therefore doesn't mean any effort, does it?

@@ -1,7 +1,7 @@
{
"name": "snowballr-mock-backend",
"version": "1.0.0",
"description": "A Mock Backend for the SnowballR Frontend Development",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not a no-go, in my experience it's just very unusual for descriptions, especially of packages. But if you want to go with this title-case I can change it back, but the version should stay 0.1, as everything can still change in the mock backend (e.g. dynamically load data at the start will be introduced soon).

Comment on lines -20 to +19
export const LOGGING_INTERCEPTOR: ServerInterceptor = function (
methodDescriptor: ServerMethodDefinition<any, any>,
export const LOGGING_INTERCEPTOR: ServerInterceptor = function <RequestT, ResponseT>(
methodDescriptor: ServerMethodDefinition<RequestT, ResponseT>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched for a solution of this problem of types for generic functions and the first solution was using Generics. Didnt know this either, but it works and seems a bit more elegant to. Or should I change it back and add a comment for the linter?

Comment on lines 48 to 50
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, i accidentally deleted this line.

Comment on lines +20 to +21
with:
submodules: "recursive"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we dont need to, but I pull the submodule to use the custom "setup" workflow (with always generate the grpc stuff and therefore need the submodule). If it is in your opinion not good practice, I can delete it and dont use the "setup" workflow.


docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

docker run -d --name snowballr-mock-backend -p 3001:3001 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first thought was, that it is not necessary, as this is the deployed mock backend and why should we use grpcui or grpcurl with this, but on the other hand, it shouldn't cause any problem to expose the other port, so I will add it.

mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "StrictHostKeyChecking no" >> ~/.ssh/config
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is, you are right (I must admit, I only copied this code and forgot to check, whether there are duplicate "lines"). I delete this line.

@Merseleo Merseleo requested a review from luca-schlecker March 7, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add initial CI/CD workflow
2 participants