Skip to content

Commit

Permalink
Merge pull request #174 from claabs/debian
Browse files Browse the repository at this point in the history
Add Debian image
  • Loading branch information
claabs authored Oct 22, 2021
2 parents f5a7340 + 21b692a commit ddf16a4
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 6 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/build_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push master
- name: Build and push master (Alpine)
if: ${{ github.ref == 'refs/heads/master' }}
uses: docker/build-push-action@v2
with:
Expand All @@ -55,6 +55,21 @@ jobs:
COMMIT_SHA=${{ github.sha }}
BRANCH=${{ env.GIT_BRANCH }}
- name: Build and push master (Debian)
if: ${{ github.ref == 'refs/heads/master' }}
uses: docker/build-push-action@v2
with:
target: deploy
push: true
file: Dockerfile.debian
tags: |
charlocharlie/epicgames-freegames:bullseye-slim
ghcr.io/claabs/epicgames-freegames-node:bullseye-slim
platforms: linux/amd64
build-args: |
COMMIT_SHA=${{ github.sha }}
BRANCH=${{ env.GIT_BRANCH }}
- name: Build and push dev
if: ${{ github.ref == 'refs/heads/develop' }}
uses: docker/build-push-action@v2
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/snyk-container-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v2
# - name: Build a Docker image
# run: docker build -t ghcr.io/claabs/epicgames-freegames-node:latest .
- name: Run Snyk to check Docker image for vulnerabilities
- name: Scan Alpine image
# Snyk can be used to break the build when it detects vulnerabilities.
# In this case we want to upload the issues to GitHub Code Scanning
continue-on-error: true
Expand All @@ -38,6 +38,19 @@ jobs:
with:
image: ghcr.io/claabs/epicgames-freegames-node:latest
args: --file=Dockerfile
- name: Scan Debian image
# Snyk can be used to break the build when it detects vulnerabilities.
# In this case we want to upload the issues to GitHub Code Scanning
continue-on-error: true
uses: snyk/actions/docker@master
env:
# In order to use the Snyk Action you will need to have a Snyk API token.
# More details in /~https://github.com/snyk/actions#getting-your-snyk-token
# or you can signup for free at https://snyk.io/login
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: ghcr.io/claabs/epicgames-freegames-node:bullseye-slim
args: --file=Dockerfile.debian
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
########
FROM node:14-alpine3.14 as base

ENV DISTRO=alpine
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1

WORKDIR /usr/app
Expand Down
91 changes: 91 additions & 0 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
########
# BASE
########
FROM node:14-bullseye-slim as base

ENV DISTRO=debian
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1

WORKDIR /usr/app

########
# BUILD
########
FROM base as build

# Copy all source files
COPY package*.json tsconfig.json ./

# Add dev deps
RUN npm ci

# Copy source code
COPY src src

RUN npm run build

########
# DEPS
########
FROM base as deps

# Chromium dependencies /~https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
# The Google Chrome apt list only seems to provide the latest version, so version compatibility with puppeteer is questionable
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
google-chrome-stable \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-freefont-ttf \
libxss1 \
# App dependencies
jq \
tzdata \
cron \
&& rm -rf /var/lib/apt/lists/*

########
# DEPLOY
########
FROM deps as deploy

# Copy package.json for version number
COPY package*.json ./

RUN npm ci --only=production

# Steal compiled code from build image
COPY --from=build /usr/app/dist ./dist

COPY entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# backwards compat (from https://success.docker.com/article/use-a-script-to-initialize-stateful-container-data)
RUN ln -s /usr/local/bin/docker-entrypoint.sh /

ARG COMMIT_SHA="" \
BRANCH=""

LABEL org.opencontainers.image.title="epicgames-freegames-node" \
org.opencontainers.image.url="/~https://github.com/claabs/epicgames-freegames-node" \
org.opencontainers.image.description="Automatically redeem free games promotions on the Epic Games store" \
org.opencontainers.image.name="epicgames-freegames-node" \
org.opencontainers.image.revision=${COMMIT_SHA} \
org.opencontainers.image.ref.name=${BRANCH} \
org.opencontainers.image.base.name="node:14-bullseye-slim" \
org.opencontainers.image.version="latest"

ENV NODE_ENV=production \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable \
COMMIT_SHA=${COMMIT_SHA} \
BRANCH=${BRANCH}

EXPOSE 3000

VOLUME [ "/usr/app/config" ]

ENTRYPOINT ["docker-entrypoint.sh"]
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ This image is available from both [GitHub Container Registry](https://github.com
* `ghcr.io/claabs/epicgames-freegames-node:latest`
* `charlocharlie/epicgames-freegames:latest`

If you're [experiencing issues with Chromium starting](/~https://github.com/claabs/epicgames-freegames-node/issues/164) (hangs on login/notification), you can try the Debian image:

* `ghcr.io/claabs/epicgames-freegames-node:bullseye-slim`
* `charlocharlie/epicgames-freegames:bullseye-slim`

If you are using full JSON configuration, the only remaining Docker configurables are the [port](#ports) and [volume](#volumes).

#### Environment Variables
Expand Down
17 changes: 13 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ fi
echo "Run once: ${RUN_ONCE}"
if [ "$RUN_ONCE" = "false" ]; then
echo "Setting cron schedule as ${CRON_SCHEDULE}"
# Add the command to the crontab
echo "${CRON_SCHEDULE} cd /usr/app && node /usr/app/dist/src/index.js" | crontab -
# Run the cron process. The container should halt here and wait for the schedule.
/usr/sbin/crond -f -l 8
if [ "$DISTRO" = "alpine" ]; then
# Add the command to the crontab
echo "${CRON_SCHEDULE} cd /usr/app && node /usr/app/dist/src/index.js" | crontab -
# Run the cron process. The container should halt here and wait for the schedule.
/usr/sbin/crond -f -l 8
else
# Debian cron wipes the environment, so we save it to a script to load in cron
printenv | sed 's/^\(.*\)$/export \1/g' > /root/project_env.sh
# Add the command to the crontab
echo "${CRON_SCHEDULE} . /root/project_env.sh && cd /usr/app && node /usr/app/dist/src/index.js > /proc/1/fd/1 2>/proc/1/fd/2" | crontab -
# Run the cron process. The container should halt here and wait for the schedule.
cron -f
fi
fi
echo "Exiting..."
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"redeem": "ts-node commands.ts redeem",
"create": "ts-node commands.ts create",
"docker:build": "docker build . -t charlocharlie/epicgames-freegames-node:latest --target deploy",
"docker:build-debian": "docker build . -t charlocharlie/epicgames-freegames-node:bullseye-slim --target deploy --file Dockerfile.debian",
"docker:build-dev": "docker build . -t charlocharlie/epicgames-freegames:dev --target deploy",
"docker:run": "docker run --rm -ti -v $(pwd)/config:/usr/app/config -p 3000:3000 -p 3001:3001 charlocharlie/epicgames-freegames-node:latest",
"docker:run-debian": "docker run --rm -ti -v $(pwd)/config:/usr/app/config -p 3000:3000 -p 3001:3001 charlocharlie/epicgames-freegames-node:bullseye-slim",
"docs": "typedoc --out docs src/common/config/classes.ts && cp test/test.html docs"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function main(): Promise<void> {
}
const accountPromises = config.accounts.map(redeemAccount);
await Promise.all(accountPromises);
exit(0); // For some reason, puppeteer will keep a zombie promise alive and stop Node from exiting
}
}

Expand Down

0 comments on commit ddf16a4

Please sign in to comment.