From 53a9ef36327412a0f6b1a7eb367a66f85ba85cca Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sat, 17 Feb 2024 16:04:22 +0100 Subject: [PATCH] Add Github workflow and rework docker file (#3) --- .github/workflows/armit.yml | 45 ++++++++++++++++++++++++++++++++++ Dockerfile | 48 +++++++++---------------------------- 2 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/armit.yml diff --git a/.github/workflows/armit.yml b/.github/workflows/armit.yml new file mode 100644 index 0000000..274e5a3 --- /dev/null +++ b/.github/workflows/armit.yml @@ -0,0 +1,45 @@ +name: ArmIT +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + build: + name: Build + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Use Node.js 20 + uses: actions/setup-node@v3 + with: + node-version: 20 + - run: npm install --frozen-lockfile + - run: npm run build + + docker: + name: Build docker container + + permissions: + packages: write + + needs: [build] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + if: ${{ github.ref == 'refs/heads/main' }} + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build Docker image (and push on main) + uses: docker/build-push-action@v4.0.0 + with: + push: ${{ github.ref == 'refs/heads/main' }} + tags: ghcr.io/cthit/armit:latest diff --git a/Dockerfile b/Dockerfile index ecc13c4..0713810 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,16 @@ -# Use an official Node.js image as a base image -FROM node:18-alpine - -# Set the working directory inside the container +FROM node:20-alpine AS builder WORKDIR /app - -# Copy package.json and package-lock.json to the working directory -COPY package*.json ./ - -# Install dependencies -RUN npm install - -# Copy the rest of the application code to the working directory +COPY package*.json . +RUN npm ci COPY . . - -# Build the SvelteKit app with Vite RUN npm run build +RUN npm prune --production -#Expose port +FROM node:20-alpine +WORKDIR /app +COPY --from=builder /app/build build/ +COPY --from=builder /app/node_modules node_modules/ +COPY package.json . EXPOSE 3000 - -#Start the app -CMD ["npm", "run", "preview"] - - -#Should the above not work, use this: - -# FROM node:17-alpine - -# WORKDIR /app - -# COPY package*.json ./ - -# RUN npm install --legacy-peer-deps - -# COPY . . - -# RUN npm run build - -# EXPOSE 3000 - -# CMD ["npm", "run", "dev"] \ No newline at end of file +ENV NODE_ENV=production +CMD [ "node", "build" ] \ No newline at end of file