interaapps/pastefy

Unable to build docker image for ARM

cinetube opened this issue · 5 comments

I have tried to build arm docker image of Pastefy but the build process is getting terminated in the mid way. Please check the issue.

There's a couple things going on here. Before I dive into that, I wanted to note that I was able to build the image successfully on my Raspberry Pi 4 after making these changes. The title of the says 'ARM' but there are quite a few variants of the ARM processor, so I have no idea which one @cinetube is referring too.

Of note, in the future @cinetube I would recommend posting your failed build output/logs, and be more specific in the environment and hardware you're having trouble on.

  1. I came across this first issue recently with another Alpine based Docker image I was using. The problem is that it looks like Python is required but you must specify the version when installing the Python package (see this on StackOverflow). In this case it looks like the build process was trying to use Python 2.x. I updated the Dockerfile to include a command to install Python 2.x. I added this right after the first line (FROM node:lts-alpine as frontend).

RUN apk add g++ make python2

  1. I was seeing a lot of messaging about the package-lock.json file being outdated so I removed the following files:
  • package-lock.json
  • frontend/package-lock.json

These lock files will be rebuilt properly when the npm install command is run.

  1. Since the Docker image is using node:lts-alpine this means (at the time of writing) NodeJS 16.x will be installed. The NPM module node-sass will no longer work in NodeJS 16.x (see this, this and [this]https://sass-lang.com/blog/libsass-is-deprecated) .

Easy enough to fix though. Open up frontend/package.json and replace "node-sass": "^4.14.1", with "sass": "^1.43.4",.

This should be enough information if anyone wants to make a PR. Below you can find the full contents of the files I adjusted to get this to build.

Here is my full Dockerfile:

FROM node:lts-alpine as frontend
RUN apk add g++ make python2
WORKDIR /
COPY frontend/package*.json ./app/

RUN npm --prefix app install
COPY frontend app
RUN npm run --prefix app build --prod


FROM maven:3.6.0-jdk-8-slim AS build

WORKDIR /

COPY backend/src /home/app/src
COPY backend/pom.xml /home/app
COPY --from=frontend backend/src/main/resources/static /home/app/src/main/resources/static
RUN mvn -f /home/app/pom.xml clean package

FROM openjdk:8-jre-slim
COPY --from=build /home/app/target/backend.jar /usr/local/lib/backend.jar
# COPY .env .env

EXPOSE 1337
ENTRYPOINT ["java","-jar","/usr/local/lib/backend.jar", "start"]

and here is my full frontend/package.json file:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "babel-polyfill": "^6.26.0",
    "core-js": "^3.6.5",
    "markdown-it": "^12.0.4",
    "vue": "^2.6.11",
    "vue-router": "^3.5.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "babel-eslint": "^10.1.0",
    "cajaxjs": "^3.0.4",
    "crypto-js": "^4.0.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "jdomjs": "^1.1.2",
    "sass": "^1.43.4",
    "sass-loader": "^7.3.1",
    "scss-loader": "0.0.1",
    "vue-template-compiler": "^2.6.11",
    "vuex": "^3.5.1"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

@jimmybrancaccio Thanks for your reply. I will try to build the docker image again and post my update.

@jimmybrancaccio Thank you very much for your help. With the changes suggested by you I have built the docker image and can use it on my raspberry pi. Thanks.

Hey, thanks for letting me know.
I tried to fix the bugs, you might check it on your pi (I am currently not able to). You can find the fixed on docker hub https://hub.docker.com/r/interaapps/pastefy (6.3.3). Thanks to @jimmybrancaccio

Update: I've tested it on my pi and it works. The dockerhub-version obviously doesn't, so you must build it yourself. I might get into how I can use arm in github actions