From 3d42170c3d609082ab3394407dba5244c4dbe338 Mon Sep 17 00:00:00 2001 From: "tom.mansion" Date: Sun, 7 Apr 2024 21:05:27 +0200 Subject: [PATCH] Continuous deployment ready --- .github/workflows/continuous-deployment.yml | 50 +++++++++++++++++ README.md | 61 +++++++++++++++++++-- backend/utils/database_utils.py | 1 - cspell.json | 1 + makefile | 3 + 5 files changed, 109 insertions(+), 7 deletions(-) create mode 100755 .github/workflows/continuous-deployment.yml diff --git a/.github/workflows/continuous-deployment.yml b/.github/workflows/continuous-deployment.yml new file mode 100755 index 0000000..2aae238 --- /dev/null +++ b/.github/workflows/continuous-deployment.yml @@ -0,0 +1,50 @@ +name: Continuous Deployment + +on: + push: + branches: + - main + +# Declare variables +env: + APP_NAME: web_app_template + +jobs: + build: + name: Build the docker image + runs-on: ubuntu-20.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to docker hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build the Docker image + run: docker build . -t ${{ env.APP_NAME }} + + - name: Tag the Docker image with latest and the tag name + run: | + echo ${{ github.sha }} + docker tag ${{ env.APP_NAME }} ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest + + - name: Upload Docker image to Docker Hub + run: docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }} --all-tags + + deploy: + needs: build + name: Deploy to hosted server + runs-on: ubuntu-20.04 + steps: + - name: Remote ssh + uses: appleboy/ssh-action@master + with: + host: ${{secrets.SSH_HOST}} + username: ${{secrets.SSH_USER}} + password: ${{secrets.SSH_PASSWORD}} + port: ${{secrets.SSH_PORT}} + script: ${{secrets.SSH_PASSWORD}} diff --git a/README.md b/README.md index bdba56f..4686557 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,46 @@ docker-compose up --build The application should be available at: [http://localhost:3000](http://localhost:3000) +### Setting up the GitHub continuous deployment pipeline + +This project includes a GitHub Actions workflow that builds the Docker image, pushes it to the Docker Hub image registry, and deploys the application by calling an SSH script. + +#### Prerequisites + +- A Linux server with Docker and Docker Compose installed. +- A [Docker Hub](https://hub.docker.com/) account. + +#### Steps + +1. Create a new repository from this template and push it to GitHub. +2. Copy and edit the [`docker-compose.yml`](docker-compose.yml) file to your server. + - Edit the images to point to your Docker Hub repository. + - Edit the environment variables to match your configuration. + - Edit the container names and the other configurations as needed. + - Add your Nginx or Traefik configuration if needed. +3. Create, on your server a `deploy.sh` script with the following content: + +```bash +# deploy.sh +cd /path/to/your/application +docker-compose pull +docker-compose up -d +# Use chmod +x deploy.sh to make the script executable +``` + +4. Add the following secrets to your repository: + - `DOCKER_USERNAME`: Your Docker Hub username. + - `DOCKER_PASSWORD`: Your Docker Hub password. + - `SSH_HOST`: The IP address of the server where you want to deploy the application. + - `SSH_PORT`: The port to connect to the server. + - `SSH_USERNAME`: The username to connect to the server. + - `SSH_PASSWORD`: The user password to connect to the server. + - `SSH_SCRIPT_PATH`: The absolute path to the `deploy.sh` script on the server. +5. Modify the `APP_NAME`in the [continuous-deployment.yml](./.github/workflows/continuous-deployment.yml) file to match your application name. +6. Push the changes to your repository. + +The GitHub Actions workflow will run when you push the changes to the repository `main` branch. It will build the Docker image, push it to the Docker Hub image registry, and deploy the application by calling the `deploy.sh` script on your server. + ### Recommended VSCode extensions - [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) @@ -161,14 +201,23 @@ The application should be available at: [http://localhost:3000](http://localhost - [flake8](https://marketplace.visualstudio.com/items?itemName=ms-python.flake8) - [cSpell](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) +## Help + +If you have any questions or need help, feel free to [open an issue](https://github.com/Tomansion/Vue3-FastAPI-WebApp-template/issues). + +## Contributing + +I'm open to contributions and suggestions. Feel free to [open an issue](https://github.com/Tomansion/Vue3-FastAPI-WebApp-template/issues) or a make a pull request. + ## TODO -- [ ] Add i18n -- [ ] Add demo link -- [ ] Add custom styles -- [ ] Add authentication -- [ ] Add CI/CD pipeline -- [ ] Add frontend tests +- [ ] CI/CD pipeline +- [ ] Demo link +- [ ] Custom styles +- [ ] I18n +- [ ] Authentication +- [ ] Frontend tests +- [ ] Frontend to mobile app - [x] Pinia store - [x] Arango Database - [x] Backend tests and coverage diff --git a/backend/utils/database_utils.py b/backend/utils/database_utils.py index cdbe362..d3d0437 100644 --- a/backend/utils/database_utils.py +++ b/backend/utils/database_utils.py @@ -102,7 +102,6 @@ def get_notes() -> List[dict]: @db_must_be_setup def get_note(note_id) -> Optional[dict]: - print(f" - Getting note {colored(note_id, DEBUG_COLOR)}") note = db.collection(NOTES_COLLECTION_NAME).get(note_id) if note is not None: note["id"] = note["_key"] diff --git a/cspell.json b/cspell.json index 49b9fbf..223e899 100644 --- a/cspell.json +++ b/cspell.json @@ -27,6 +27,7 @@ "socketio", "termcolor", "tomansion", + "Traefik", "unplugin", "uvicorn", "Vetur", diff --git a/makefile b/makefile index 3249a51..0cc36ed 100644 --- a/makefile +++ b/makefile @@ -15,6 +15,9 @@ run_frontend: run: make run_backend & make run_frontend +start: + make runk + # Testing install_test: pip install coverage pytest pytest-cov