From 4902c655bee0de8ac1df8dd406b9da2b6b883ae2 Mon Sep 17 00:00:00 2001 From: Xander Salathe Date: Thu, 13 Feb 2025 13:27:39 +1100 Subject: [PATCH] feat: github actions - reset demo db daily, update dockerhub image on commit * feat: github action - reset demo db on cron job * feat: github action - update dockerhub image --- .github/workflows/docker-image.yml | 39 ++++++++++++++++++++++++++++++ .github/workflows/reset-db.yml | 28 +++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/reset-db.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..4653dea --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,39 @@ +name: Docker Image Pipeline + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Log in to DockerHub + run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + + - name: Build Docker Image + run: | + docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aftermath-archive-backend:latest \ + -t ${{ secrets.DOCKERHUB_USERNAME }}/aftermath-archive-backend:${{ github.sha }} . + + - name: Push Docker Image to DockerHub + run: | + docker push ${{ secrets.DOCKERHUB_USERNAME }}/aftermath-archive-backend:latest + docker push ${{ secrets.DOCKERHUB_USERNAME }}/aftermath-archive-backend:${{ github.sha }} diff --git a/.github/workflows/reset-db.yml b/.github/workflows/reset-db.yml new file mode 100644 index 0000000..414687e --- /dev/null +++ b/.github/workflows/reset-db.yml @@ -0,0 +1,28 @@ +name: Reset MongoDB Demo Data + +on: + schedule: + - cron: '0 0 * * *' # Runs daily at midnight UTC + workflow_dispatch: + +jobs: + reset-db: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Drop and Seed Database + run: npm run db:drop-and-seed + env: + MONGO_URI: ${{ secrets.DATABASE_URL }} \ No newline at end of file