diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 17aadb7..da214cc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,9 +1,12 @@ -name: docker +name: Docker Build and Test on: push: branches: - "master" + pull_request: + branches: + - "master" jobs: build: @@ -11,17 +14,52 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + - name: Login to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Build and push + + # Build and push: If this is a push to master, tag as 'latest' + - name: Build and push (production) + if: github.ref == 'refs/heads/master' uses: docker/build-push-action@v3 with: context: . file: ./Dockerfile + platforms: linux/amd64,linux/arm64 push: true tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sort-google-scholar:latest + + # Build and push: If this is a pull request, push to a 'test' tag + - name: Build and push (test) + if: github.event_name == 'pull_request' + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sort-google-scholar:test + + # Pull and test the production image (only for master branch pushes) + - name: Pull the image from Docker Hub (production) + if: github.ref == 'refs/heads/master' + run: docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/sort-google-scholar:latest + + - name: Test Docker Image (production) + if: github.ref == 'refs/heads/master' + run: docker run --rm ${{ secrets.DOCKER_HUB_USERNAME }}/sort-google-scholar:latest "deep learning" --nresults 20 + + # Pull and test the test image (only for PRs) + - name: Pull the image from Docker Hub (test) + if: github.event_name == 'pull_request' + run: docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/sort-google-scholar:test + + - name: Test Docker Image (test) + if: github.event_name == 'pull_request' + run: docker run --rm ${{ secrets.DOCKER_HUB_USERNAME }}/sort-google-scholar:test "deep learning" --nresults 10 diff --git a/Dockerfile b/Dockerfile index 8d18de5..ab4a07a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,17 @@ -FROM python:3.10-slim +# Use a lightweight Python base image +FROM python:3.11-slim -WORKDIR /usr/src/app +# Set environment variables to ensure Python doesn't buffer outputs +ENV PYTHONUNBUFFERED=1 -COPY requirements.txt ./ -RUN python -m pip install --upgrade pip \ - && pip install --no-cache-dir -r requirements.txt +# Set the working directory in the container +WORKDIR /app -COPY . . +# Install sortgs from pip +RUN pip install sortgs -CMD [ './sortgs.py' ] +# Set the entry point to use sortgs as the default command +ENTRYPOINT ["sortgs"] + +# By default, run sortgs with an example search keyword +CMD ["--help"] diff --git a/README.md b/README.md index 73add25..a6765af 100644 --- a/README.md +++ b/README.md @@ -184,14 +184,13 @@ This guide will walk you through the process of installing Docker, pulling the ` ### Step 3: Run the Project -1. **Create a Results Directory**: Create a directory on your host machine where you want the results to be saved. For example, `mkdir ~/results`. -2. **Run the Docker Container**: Use the following command to run the container. This command mounts your results directory to the `/results` directory in the container and starts the sorting process for Google Scholar results based on your specified parameters. +1. **Run the Docker Container**: Use the following command to run the container: ```bash - docker run -v "$PWD/results:/results" -it fernandowittmann/sort-google-scholar ./sortgs.py --kw "machine learning" --sortby "cit/year" --csvpath /results + docker run -v "$PWD/sortgs-results:/app" fernandowittmann/sort-google-scholar "machine learning" ``` - Replace `$PWD/results` with the absolute path to your results directory if you are not in the parent directory of `results`. + Replace `$PWD` with the absolute path to your results directory if you are not in the parent directory of `sortgs-results`. ## Contributing