From eb57bc2000a4cdf475086fd56098b49bfa8646d7 Mon Sep 17 00:00:00 2001 From: mmd-afegbua Date: Tue, 9 Jan 2024 16:36:42 +0100 Subject: [PATCH] added pr build --- .github/workflows/pr-docker-push.yml | 30 ++++++++++++++++ ...ocker-push.yml => release-docker-push.yml} | 0 Dockerfile | 34 +++++++++++-------- 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/pr-docker-push.yml rename .github/workflows/{docker-push.yml => release-docker-push.yml} (100%) diff --git a/.github/workflows/pr-docker-push.yml b/.github/workflows/pr-docker-push.yml new file mode 100644 index 00000000..6404cb8e --- /dev/null +++ b/.github/workflows/pr-docker-push.yml @@ -0,0 +1,30 @@ +name: Build Docker Image on PR to ref main branch + +on: + pull_request: + branches: + - 'master' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout out the repo + uses: actions/checkout@v2 + + - name: Log into the Container registry + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Set Docker tag as short commit sha + id: tag + run: echo "::set-output name=TAG::$(echo $GITHUB_SHA | head -c 8)" + + - name: Build and push the Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO }}:${{ steps.tag.outputs.TAG }} diff --git a/.github/workflows/docker-push.yml b/.github/workflows/release-docker-push.yml similarity index 100% rename from .github/workflows/docker-push.yml rename to .github/workflows/release-docker-push.yml diff --git a/Dockerfile b/Dockerfile index 4ef3ad24..a8aeb150 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,33 @@ # syntax = docker/dockerfile:1.3 -# Always add commit hash for reproducability +# Always add commit hash for reproducibility FROM node:18-alpine@sha256:3482a20c97e401b56ac50ba8920cc7b5b2022bfc6aa7d4e4c231755770cf892f # Enable prod optimizations -ENV NODE_ENV=production +ENV NODE_ENV=production \ + NPM_CONFIG_PRODUCTION=false WORKDIR /app -RUN apk add --update --no-cache g++ make python3 && \ - ln -sf python3 /usr/bin/python && \ - apk add --update --no-cache yarn +# Install build dependencies and clean up +RUN apk add --update --no-cache \ + g++ \ + make \ + python3 \ + && ln -sf python3 /usr/bin/python \ + && apk add --update --no-cache yarn \ + && apk add --no-cache tini \ + && rm -rf /var/cache/apk/* + +# Copy package.json and yarn.lock for optimised caching COPY ["package.json", "yarn.lock", "./"] -RUN yarn install --frozen-lockfile --production -COPY . /app -# make sure we can write the data directory -RUN chown node:node data +# Make sure we can write the data directory +RUN mkdir -p data + +# Install application dependencies +RUN yarn install --frozen-lockfile --production -# Add a simple init system so that Node would respect process signals -RUN apk add --no-cache tini ENTRYPOINT ["/sbin/tini", "--"] -# Don't run as root -USER node -CMD ["node", "main.js" ] +CMD ["node", "main.js"]