Skip to content
Open
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
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy to S3

on:
push:
branches:
- static-website-project2 # This will trigger the action when you push to the main branch

jobs:
deploy:
runs-on: ubuntu-latest # This will run on the latest Ubuntu machine

steps:
- name: Checkout code
uses: actions/checkout@v2 # Checks out your code from the repository

- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-south-1 # Change this to your AWS region if needed

- name: Sync to S3
run: |
aws s3 sync . s3://pavithra-static-site/ --exclude ".git/*" --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
183 changes: 75 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,136 +1,103 @@
<p align="center">
<a href="https://www.medusajs.com">
<img alt="Medusa" src="https://user-images.githubusercontent.com/7554214/153162406-bf8fd16f-aa98-4604-b87b-e13ab4baf604.png" width="100" />
</a>
</p>
<h1 align="center">
Medusa
</h1>

<h4 align="center">
<a href="https://github.com/medusajs/admin">Medusa Admin</a> |
<a href="https://www.medusajs.com">Website</a> |
<a href="https://www.medusajs.com/blog">Blog</a> |
<a href="https://www.linkedin.com/company/medusa-commerce">LinkedIn</a> |
<a href="https://twitter.com/medusajs">Twitter</a> |
<a href="https://docs.medusajs.com">Documentation</a> |
<a href="https://medusajs.notion.site/medusajs/Medusa-Home-3485f8605d834a07949b17d1a9f7eafd">Notion</a>
</h4>

<p align="center">
Medusa is an open-source headless commerce engine that enables developers to create amazing digital commerce experiences.
</p>
<p align="center">
<a href="https://github.com/medusajs/medusa/blob/master/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
</a>
<a href="https://github.com/medusajs/medusa/blob/master/CONTRIBUTING.md">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
</a>
<a href="https://www.producthunt.com/posts/medusa"><img src="https://img.shields.io/badge/Product%20Hunt-%231%20Product%20of%20the%20Day-%23DA552E" alt="Product Hunt"></a>
<a href="https://discord.gg/xpCwq3Kfn8">
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
</a>
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
<img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
</a>
</p>


## Please note
This repo is managed by the Medusa Community. Medusa does not provide official support for Docker, but we will accept fixes and documentation. Use at your own risk.

**This project is inteded for development only at this time.**

The files for both the <i>Medusa server</i> and the <i>Storefront</i> are loaded in Bind Mounts allowing you to change the server functionality and have the change be hot-reloaded onto your running containers.

</p>
# Static Website with AWS S3, GitHub Actions, and Netlify

This project demonstrates how to deploy a static website using **AWS S3**, **GitHub Actions**, and **Netlify** to enable a seamless Continuous Integration and Continuous Deployment (CI/CD) pipeline. We also explore why **Netlify** was chosen over Cloudflare and S3 directly for hosting.

## Project Overview

This project automates the deployment of a static website through the following process:

1. **GitHub Actions**: Automates the deployment pipeline when changes are made to the GitHub repository.
2. **AWS S3**: Hosts the static files (HTML, CSS, etc.) of the website.
3. **Netlify**: Simplifies deployment and automatically provides HTTPS, enabling a secure connection to the website.
4. **CI/CD Workflow**: Every time you push changes to the GitHub repository, **GitHub Actions** ensures that the website is deployed automatically to **Netlify** for public access.

### Tools Used:

* **GitHub Actions**: To automate deployment whenever changes are pushed to the GitHub repository.
* **AWS S3**: Used for hosting the static files of the website.
* **Netlify**: Provides seamless integration for deploying the website with automatic HTTPS support and continuous deployment.
* **Cloudflare**: Initially considered for DNS management and HTTPS, but ultimately not required for the free deployment flow with **Netlify**.

---

## Requirements
## Steps We Followed

### 1. **Create a Static HTML Site**

We began by designing a simple static HTML site using basic HTML and CSS to demonstrate the deployment. The structure consisted of:

* `index.html`
* `style.css`
* `README.md`

![image](https://github.com/user-attachments/assets/6b757979-4741-4803-a030-289cd277d62f)

To use Docker with Medusa, you should have created a Medusa project. Check out our [Quickstart](https://github.com/medusajs/medusa#quickstart) to get started.

Additionally, you should have `docker` and `docker-compose` installed on your system.
### 2. **Set Up GitHub Actions for CI/CD**

## Getting Started
* We created a GitHub repository to store the website files.
* We configured a GitHub Actions workflow that syncs the changes made to the repository with **Netlify** (via the API), so whenever a commit is pushed to the `main` branch, the website is updated automatically.

To set up Medusa in a development environment with Docker, you should copy files `docker-compose.yml`, `docker-compose.override.yml, `backend/develop.sh`, and `backend/Dockerfile` to your Medusa project.

Then build the images since they are not published on dockerhub. This is accomplished by adding the `--build` flag as shown below:
![image](https://github.com/user-attachments/assets/27303353-d6b5-4748-a111-1c695f1482a5)

```bash
docker compose up --build
```

Having already built the Docker images you can run docker compose without the `--build` flag.
### 3. **Deployment to Netlify**

```
docker compose up
```
* We connected the GitHub repository to **Netlify** for hosting the static files.
* **Netlify** provides automatic HTTPS via SSL certificates, ensuring that the website has a secure connection.
* After connecting the repository to Netlify, the website was live on a custom subdomain provided by Netlify (`<your-site-name>.netlify.app`).

Your local Medusa setup is now running with each of the services occupying the following ports:

<ul>
<li><b>Medusa Server</b>: 9000
<li><b>Medusa Admin</b>: 7000
<li><b>Storefront</b>: 8000
<li><b>postgres</b>: 5432
<li><b>redis</b>: 6379
</ul>
![image](https://github.com/user-attachments/assets/ac097032-4df3-49a8-9d07-a2359b82e70d)

_Note: If you change the dependencies of your projects by adding new packages you can simply rebuild that package with the same tag `test` and run `docker compose up` once again to update your environment._

### Seeding your Medusa store
### 4. **Choosing Netlify Over AWS S3 + Cloudflare**

To add seed data to your medusa store run this command in a seperate
* We initially explored using **AWS S3** and **Cloudflare** for hosting the website.
* However, **Netlify** was chosen as a more streamlined solution due to its built-in features like:

```
docker exec medusa-server medusa seed -f ./data/seed.json
```
* Automatic HTTPS (SSL).
* Simple deployment via GitHub.
* Free tier for personal projects.
* Easy custom domain management.

## Running Medusa with docker in production
### 5. **Final Website URL**

This repository and each of the services contain dockerfiles for both development and production, named `Dockerfile` and `Dockerfile.prod` respectively. The `Dockerfile.prod` copies the local files from disk and builds a production ready image based on your local development progress. Your specific needs for a production like container might differ from the `Dockerfile.prod` but it should provide a template and an idea of the requirements for each of the basic services.
* The final static website is deployed on **Netlify** with the URL:
[https://pavithra-static-app.netlify.app](https://pavithra-static-app.netlify.app).

To run the services in a production state `docker compose` is simply run with the `docker-compose.production.yml` file as well as the basic `docker-compose.yml` file as seen below. If you wish to build the production ready images and then start them run `docker compose up` with the `--build` flag as described above.
![image](https://github.com/user-attachments/assets/071b85df-b8b3-4188-a6e3-b402eee5ea9c)

```
docker compose up -f docker-compose.yml -f docker-compose.production.yml up
```

`docker-compose.production.yml` contains production relevant overrides to the services described in the `docker-compose.yml` development file.
### 6. **Live Demo**

## Try it out
* You can visit the live demo of the website here:
[https://pavithra-static-app.netlify.app](https://pavithra-static-app.netlify.app).

```
curl -X GET localhost:9000/store/products | python -m json.tool
```
### 7. **Explanation Video**

After the seed script has run you will have the following things in you database:
* (https://drive.google.com/file/d/1mrRn3U1aFUM10rU2ypewy0xRhuzzZ20H/view?usp=sharing)

- a User with the email: [email protected] and password: supersecret
- a Region called Default Region with the countries GB, DE, DK, SE, FR, ES, IT
- a Shipping Option called Standard Shipping which costs 10 EUR
- a Product called Cool Test Product with 4 Product Variants that all cost 19.50 EUR
---

## Key Features

* **Automatic Deployment**: Every change pushed to GitHub triggers an automatic deployment to Netlify via **GitHub Actions**.
* **Secure Connection (HTTPS)**: The website is served securely over HTTPS with SSL certificates automatically provided by **Netlify**.
* **Continuous Integration and Continuous Deployment (CI/CD)**: No manual intervention is required. Once a commit is made to GitHub, the website updates automatically.

---

## Deliverables

* **GitHub Actions CI/CD Workflow**: Automates the deployment process.
* **Cloudflare + S3 Integration Steps**: Although **Cloudflare** and **S3** were initially planned for DNS and hosting, **Netlify** was used instead for easier setup and features.
* **Live Website Link with HTTPS**: Available at [https://pavithra-static-app.netlify.app](https://pavithra-static-app.netlify.app).
* **Screenshot & Deployment Report**: Screenshots of the live website and deployment steps are included as part of the documentation.

---

Visit [docs.medusa-commerce.com](https://docs.medusa-comerce.com) for further guides.
## Conclusion

<p>
<a href="https://www.medusa-commerce.com">
Website
</a>
|
<a href="https://medusajs.notion.site/medusajs/Medusa-Home-3485f8605d834a07949b17d1a9f7eafd">
Notion Home
</a>
|
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
Twitter
</a>
|
<a href="https://docs.medusa-commerce.com">
Docs
</a>
</p>
In this project, we learned how to automate the deployment of a static website with GitHub Actions, AWS S3, and **Netlify**. Although we initially considered using **Cloudflare** and **S3** for hosting, we switched to **Netlify** due to its ease of use and built-in features such as automatic HTTPS and continuous deployment from GitHub.
21 changes: 0 additions & 21 deletions admin/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions admin/Dockerfile.prod

This file was deleted.

19 changes: 0 additions & 19 deletions backend/Dockerfile

This file was deleted.

47 changes: 0 additions & 47 deletions backend/Dockerfile.prod

This file was deleted.

5 changes: 0 additions & 5 deletions backend/develop.sh

This file was deleted.

25 changes: 0 additions & 25 deletions docker-compose.override.yml

This file was deleted.

Loading