feat(docker): add docker and publish images to ghcr (#411)

Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
VictorV
2020-10-09 14:42:29 -07:00
committed by GitHub
parent e1cae3ed71
commit c857985a6d
8 changed files with 147 additions and 54 deletions
+6
View File
@@ -0,0 +1,6 @@
.idea/
.git/
.vs/
.vscode/
build/
node_modules/
+49 -53
View File
@@ -2,56 +2,52 @@
# Read https://github.com/jef/nvidia-snatcher#customization for help on customizing this file # Read https://github.com/jef/nvidia-snatcher#customization for help on customizing this file
############################################################################################# #############################################################################################
BROWSER_TRUSTED="" BROWSER_TRUSTED=
COUNTRY="" COUNTRY=
DISCORD_NOTIFY_GROUP="" DISCORD_NOTIFY_GROUP=
DISCORD_WEB_HOOK="" DISCORD_WEB_HOOK=
EMAIL_USERNAME="" EMAIL_USERNAME=
EMAIL_TO="" EMAIL_TO=
EMAIL_PASSWORD="" EMAIL_PASSWORD=
HEADLESS="" HEADLESS=
IN_STOCK_WAIT_TIME="" IN_STOCK_WAIT_TIME=
LOG_LEVEL="" LOG_LEVEL=
LOW_BANDWIDTH="" LOW_BANDWIDTH=
MAX_PRICE_3070="" MAX_PRICE=
MAX_PRICE_3080="" MICROCENTER_LOCATION=
MAX_PRICE_3090="" NVIDIA_ADD_TO_CART_ATTEMPTS=
MICROCENTER_LOCATION="" NVIDIA_SESSION_TTL=
NVIDIA_ADD_TO_CART_ATTEMPTS="" OPEN_BROWSER=
NVIDIA_SESSION_TTL="" PAGE_BACKOFF_MIN=
OPEN_BROWSER="" PAGE_BACKOFF_MAX=
PAGE_BACKOFF_MIN="" PAGE_SLEEP_MIN=
PAGE_BACKOFF_MAX="" PAGE_SLEEP_MAX=
PAGE_SLEEP_MIN="" PAGE_TIMEOUT=
PAGE_SLEEP_MAX="" PHONE_NUMBER=
PAGE_TIMEOUT="" PHONE_CARRIER=
PHONE_NUMBER="" PLAY_SOUND=
PHONE_CARRIER="" PROXY_ADDRESS=
PLAY_SOUND="" PROXY_PORT=
PROXY_ADDRESS="" PUSHBULLET=
PROXY_PORT="" PUSHOVER_TOKEN=
PUSHBULLET="" PUSHOVER_USER=
PUSHOVER_TOKEN="" PUSHOVER_PRIORITY=
PUSHOVER_USER="" SCREENSHOT=
PUSHOVER_PRIORITY="" SHOW_ONLY_BRANDS=
SCREENSHOT="false" SHOW_ONLY_MODELS=
SHOW_ONLY_BRANDS="" SHOW_ONLY_SERIES=
SHOW_ONLY_MODELS="" SLACK_CHANNEL=
SHOW_ONLY_SERIES="" SLACK_TOKEN=
SLACK_CHANNEL="" STORES=
SLACK_TOKEN="" TELEGRAM_ACCESS_TOKEN=
SMTP_ADDRESS="" TELEGRAM_CHAT_ID=
SMTP_PORT="" TWILIO_ACCOUNT_SID=
STORES="" TWILIO_AUTH_TOKEN=
TELEGRAM_ACCESS_TOKEN="" TWILIO_FROM_NUMBER=
TELEGRAM_CHAT_ID="" TWILIO_TO_NUMBER=
TWILIO_ACCOUNT_SID="" TWITTER_CONSUMER_KEY=
TWILIO_AUTH_TOKEN="" TWITTER_CONSUMER_SECRET=
TWILIO_FROM_NUMBER="" TWITTER_ACCESS_TOKEN_KEY=
TWILIO_TO_NUMBER="" TWITTER_ACCESS_TOKEN_SECRET=
TWITTER_CONSUMER_KEY="" TWITTER_TWEET_TAGS=
TWITTER_CONSUMER_SECRET="" USER_AGENT=
TWITTER_ACCESS_TOKEN_KEY=""
TWITTER_ACCESS_TOKEN_SECRET=""
TWITTER_TWEET_TAGS=""
USER_AGENT=""
+22
View File
@@ -16,3 +16,25 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
release-type: node release-type: node
package-name: nvidia-snatcher package-name: nvidia-snatcher
- name: login into github package registry
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: build nightly docker image
if: ${{ ! steps.release.outputs.release_created }}
run: |
docker build \
-t "ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA:0:7}" \
-t "ghcr.io/${GITHUB_REPOSITORY}:nightly" .
- name: publish nightly
if: ${{ ! steps.release.outputs.release_created }}
run: docker push "ghcr.io/${GITHUB_REPOSITORY}"
- name: build latest docker image
if: ${{ steps.release.outputs.release_created }}
run: |
docker build \
-t "ghcr.io/${GITHUB_REPOSITORY}:${TAG_NAME}" \
-t "ghcr.io/${GITHUB_REPOSITORY}:latest" .
env:
TAG_NAME: ${{ steps.release.outputs.tag_name }}
- name: publish latest
if: ${{ steps.release.outputs.release_created }}
run: docker push "ghcr.io/${GITHUB_REPOSITORY}"
+13 -1
View File
@@ -9,7 +9,7 @@ jobs:
build-lint: build-lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@v2
- uses: actions/setup-node@v2.1.2 - uses: actions/setup-node@v2.1.2
with: with:
node-version: 14 node-version: 14
@@ -25,3 +25,15 @@ jobs:
npm ci npm ci
npm run build npm run build
npm run lint npm run lint
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
src:
- 'Dockerfile'
- name: Build image
run: docker build .
+36
View File
@@ -0,0 +1,36 @@
# Build the source code
FROM node:14.11.0-alpine3.12 AS builder
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
WORKDIR /build
COPY package.json package.json
COPY package-lock.json package-lock.json
COPY tsconfig.json tsconfig.json
RUN npm ci
COPY src/ src/
RUN npm run build
RUN npm prune --production
FROM node:14.11.0-alpine3.12
RUN apk add --no-cache chromium
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \
DOCKER=true
RUN addgroup -S appuser && adduser -S -g appuser appuser \
&& mkdir -p /home/appuser/Downloads /app \
&& chown -R appuser:appuser /home/appuser \
&& chown -R appuser:appuser /app
USER appuser
WORKDIR /app
COPY --from=builder /build/node_modules/ node_modules/
COPY --from=builder /build/build/ build/
CMD [ "node", "./build/index.js" ]
+13
View File
@@ -42,6 +42,8 @@ You do not need any computer skills, smarts, or anything of that nature. You are
### Quick overview ### Quick overview
#### Native installation
- [Node.js 14](https://nodejs.org/en/) - [Node.js 14](https://nodejs.org/en/)
- [git](https://git-scm.com/) - [git](https://git-scm.com/)
- Clone this project `git clone https://github.com/jef/nvidia-snatcher.git` - Clone this project `git clone https://github.com/jef/nvidia-snatcher.git`
@@ -54,6 +56,17 @@ At any point you want the program to stop, use <kbd>Ctrl</kbd> + <kbd>C</kbd>.
> :point_right: Please visit the [wiki](https://github.com/jef/nvidia-snatcher/wiki) if you need more help with installation. > :point_right: Please visit the [wiki](https://github.com/jef/nvidia-snatcher/wiki) if you need more help with installation.
#### Docker image (To run inside containers)
Available via GitHub Container Registry.
| Tag | Note |
|:---:|---|
| `latest` | Latest stable build |
| `nightly` | Latest HEAD build, could be unstable |
Use `docker run --cap-add=SYS_ADMIN -it --rm --env-file ./.env ghcr.io/jef/nvidia-snatcher:nightly` to run.
### Developer notes ### Developer notes
The command `npm run start:dev` can be used instead of `npm run start` to automatically restart the project when filesystem changes are detected in the `src/` folder or `.env` file. The command `npm run start:dev` can be used instead of `npm run start` to automatically restart the project when filesystem changes are detected in the `src/` folder or `.env` file.
+3
View File
@@ -118,6 +118,8 @@ const browser = {
open: envOrBoolean(process.env.OPEN_BROWSER) open: envOrBoolean(process.env.OPEN_BROWSER)
}; };
const docker = envOrBoolean(process.env.DOCKER);
const logLevel = envOrString(process.env.LOG_LEVEL, 'info'); const logLevel = envOrString(process.env.LOG_LEVEL, 'info');
const notifications = { const notifications = {
@@ -225,6 +227,7 @@ const store = {
export const config = { export const config = {
browser, browser,
docker,
logLevel, logLevel,
notifications, notifications,
nvidia, nvidia,
+5
View File
@@ -35,6 +35,11 @@ async function main() {
args.push('--disable-setuid-sandbox'); args.push('--disable-setuid-sandbox');
} }
// https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
if (config.docker) {
args.push('--disable-dev-shm-usage');
}
// Add the address of the proxy server if defined // Add the address of the proxy server if defined
if (config.proxy.address) { if (config.proxy.address) {
args.push(`--proxy-server=http://${config.proxy.address}:${config.proxy.port}`); args.push(`--proxy-server=http://${config.proxy.address}:${config.proxy.port}`);