diff --git a/q3-cicd/README.md b/q3-cicd/README.md new file mode 100644 index 0000000..d14df07 --- /dev/null +++ b/q3-cicd/README.md @@ -0,0 +1,43 @@ +# CI/CD Documentation + +## Note + +The assignment requests pushing the Docker image to a **Ghaymah Container Registry**. However, no publicly available documentation or registry endpoint could be found for a Ghaymah Container Registry. Therefore, this project uses **GitHub Container Registry (GHCR)** as the image registry while keeping the deployment workflow compatible with the documented Ghaymah CLI deployment process. + +## Staging vs Production + +### Staging + +The staging environment is a testing setup that closely mimics the production environment. It is used to validate new features, verify bug fixes, and test deployment workflows before releasing changes to end users. This helps detect issues without affecting the live application. + +### Production + +The production environment is the live environment used by real users. Deployments to production should be stable, thoroughly tested, and carefully controlled. In this project, production deployments require manual approval using GitHub Environments before the deployment job is executed. + +## Manual Approval + +The GitHub Actions workflow uses a protected `production` environment. Before the deployment job starts, GitHub pauses the workflow and waits for an authorized reviewer to approve the deployment. This provides an additional safety layer to prevent unintended production releases. + +## Connecting with Ghaymah CLI + +The available Ghaymah documentation describes deploying applications using the Ghaymah CLI. The general deployment workflow is: + +1. Install the Ghaymah CLI: + +```bash +curl -sSl https://cli.ghaymah.systems/install.sh | bash +``` + +2. Initialize the application: + +```bash +gy resource app init -p +``` + +3. Launch the application: + +```bash +gy resource app launch +``` + +The application should contain a valid `Dockerfile`, allowing the Ghaymah CLI to package and deploy the application. \ No newline at end of file diff --git a/q3-cicd/ghaymah-ci.yml b/q3-cicd/ghaymah-ci.yml new file mode 100644 index 0000000..36a94d4 --- /dev/null +++ b/q3-cicd/ghaymah-ci.yml @@ -0,0 +1,51 @@ +name: ghaymah_exam CI/CD + +on: + push: + branches: + - main + +permissions: + contents: read + packages: write + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: ./q1-deploy-monitor + file: ./q1-deploy-monitor/Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/ghaymah-exam-ahmednasser-sre:latest + ghcr.io/${{ github.repository_owner }}/ghaymah-exam-ahmednasser-sre:${{ github.sha }} + + deploy-production: + name: Deploy to Production + needs: build-and-push + runs-on: ubuntu-latest + + environment: + name: production + + steps: + - name: Deploy application + run: | + echo "Deploying image to production..." \ No newline at end of file