Skip to content

Commit

Permalink
Merge pull request #3 from ItsRaelx/main
Browse files Browse the repository at this point in the history
Add Dockerfile and automatic docker building
  • Loading branch information
akgoze authored Apr 15, 2024
2 parents f7886a1 + eda7d95 commit 09ae86f
Show file tree
Hide file tree
Showing 7 changed files with 532 additions and 434 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Docker Image CI

on:
push:
branches: [main]

jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
env:
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Convert IMAGE_NAME to lowercase
run: |
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
- name: Build the Docker image
run: |
docker build . --file Dockerfile --tag $IMAGE_NAME:${{ github.sha }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Tag the image with the 'latest' tag
run: |
docker tag $IMAGE_NAME:${{ github.sha }} ghcr.io/$IMAGE_NAME:latest
- name: Tag the image with the SHA
run: |
docker tag $IMAGE_NAME:${{ github.sha }} ghcr.io/$IMAGE_NAME:${{ github.sha }}
- name: Push the Docker image to GitHub Container Registry
run: |
docker push ghcr.io/$IMAGE_NAME:latest
docker push ghcr.io/$IMAGE_NAME:${{ github.sha }}
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use an official Node.js runtime as a parent image
FROM node:latest

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy the current directory contents into the container at /usr/src/app
COPY . .

# Install any needed packages specified in package.json
RUN npm install

# Make port 3000 available to the world outside this container
EXPOSE 3000

# Define environment variable
ENV NODE_ENV=production
ENV PORT=3000

# Run npm start when the container launches
CMD ["npm", "run", "docker"]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

Scrapper API is a Node.js API that allows you to scrape website metadata. It retrieves the `title`, `description`, `image`, and `URL` of a given web page. This API can be used to extract essential information from web pages for various purposes such as building web scrapers, generating previews, or aggregating data.

## Installation
## Installation (Using docker)

To user Scrapper API, run following command:
```sh
docker run -p 3000:3000 docker pull ghcr.io/akgoze/scrapper:latest
```

## Installation (Without docker)

To use the Scrapper API, follow these steps:

Expand Down
5 changes: 4 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const parsers_1 = require("./modules/parsers");
const app = (0, express_1.default)();
const PORT = process.env.PORT || 3000;
app.use(express_1.default.json());
app.get("/", (req, res) => {
try {
Expand All @@ -36,5 +37,7 @@ app.get("/scrapper", (req, res) => __awaiter(void 0, void 0, void 0, function* (
res.status(500).send({ error: error });
}
}));
app.listen();
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
exports.default = app;
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "Scrapper API is a Node.js API that allows you to scrape website metadata.",
"main": "index.js",
"scripts": {
"start": "jest && npx tsc",
"start": "npx tsc",
"docker": "jest && npx tsc && node dist/index.js",
"dev": "npx tsc && node dist/index.js",
"test": "jest"
},
},
"repository": {
"type": "git",
"url": "git+https://github.com/akgoze/Scrapper.git"
Expand All @@ -32,6 +33,7 @@
"cheerio": "^1.0.0-rc.12",
"express": "^4.18.2",
"install": "^0.13.0",
"jest": "^29.5.0",
"typescript": "^5.1.3"
},
"devDependencies": {
Expand All @@ -40,6 +42,7 @@
"@types/supertest": "^2.0.12",
"jest": "^29.5.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0"
"ts-jest": "^29.1.0",
"typescript": "^5.1.3"
}
}
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express, { Request, Response } from "express";
import { fetchURLMeta } from "./modules/parsers";

const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());

app.get("/", (req: Request, res: Response) => {
Expand All @@ -26,6 +27,8 @@ app.get("/scrapper", async (req: Request, res: Response) => {
}
});

app.listen();
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

export default app;
Loading

0 comments on commit 09ae86f

Please sign in to comment.