Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX #49: Docker setup and instructions #50

Merged
merged 3 commits into from
Oct 1, 2024
Merged
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
42 changes: 40 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
name: docker
name: Docker Build and Test

on:
push:
branches:
- "master"
pull_request:
branches:
- "master"

jobs:
build:
runs-on: ubuntu-latest
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
20 changes: 13 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading