Error: Docker build failed while deploying

I am trying to deploy an app that has a frontend repository, a backend repository and a data base. The backend is working but I cant deploy the frontend. When I try to do it, I see this error message: ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exit code: 126 Error: Docker build failed I dont have too much experience and I dont know how to fix it. My package.json in the front is: { "name": "client", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.11.10", "@testing-library/react": "^11.2.6", "@testing-library/user-event": "^13.1.1", "axios": "^1.2.1", "react": "^17.0.2", "react-dom": "^17.0.2", "react-redux": "^7.2.3", "react-router-dom": "^5.3.4", "react-scripts": "^5.0.1", "redux": "^4.0.5", "redux-thunk": "^2.3.0", "sweetalert2": "^11.7.1", "web-vitals": "^2.1.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }
77 Replies
Percy
Percy2y ago
Project ID: b4d47c7d-55bd-48e3-89c9-80f678c77071
Nicolás Bonder
Nicolás BonderOP2y ago
The id project is b4d47c7d-55bd-48e3-89c9-80f678c77071
Nicolás Bonder
Nicolás BonderOP2y ago
Ok, thanks. I made the changed suggested, now should I run npm build again? And should I do git add . , git commi t and git push also?
Brody
Brody2y ago
can you share your repo?
Nicolás Bonder
Nicolás BonderOP2y ago
GitHub
GitHub - nicobonder/pokemonFront: Front-end to create Pokemon App
Front-end to create Pokemon App. Contribute to nicobonder/pokemonFront development by creating an account on GitHub.
Brody
Brody2y ago
you definitely don't want to commit node_modules to your repo, please delete it and use this .gitignore file https://raw.githubusercontent.com/brody192/create-react-app-starter/main/.gitignore you also don't want to commit the build folder, so please delete that too
Nicolás Bonder
Nicolás BonderOP2y ago
ok, I will do it. Thanks
Brody
Brody2y ago
let me know when completed
Nicolás Bonder
Nicolás BonderOP2y ago
I was checking and I already have the gitignore with node_modules there. Should I have it inside the client folder?
Nicolás Bonder
Nicolás BonderOP2y ago
And I deleted the build folder
Brody
Brody2y ago
use the one I linked in your client folder
Nicolás Bonder
Nicolás BonderOP2y ago
done
Brody
Brody2y ago
push your changes
Nicolás Bonder
Nicolás BonderOP2y ago
done. SHould I remove node modules in git repo?
Brody
Brody2y ago
yes, and build folder
Nicolás Bonder
Nicolás BonderOP2y ago
I dont know if I did ok, I removed node modules in the repo, but the build folder I did it locally before to push the changes
Brody
Brody2y ago
repo looks good to me the .gitignore will prevent you from pushing the build or node_modules folder to the repo in the future automatically
Nicolás Bonder
Nicolás BonderOP2y ago
I had the same error in railway deploy: ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exit code: 1
Brody
Brody2y ago
i know follow the very last section of this guide
Nicolás Bonder
Nicolás BonderOP2y ago
ok, can you tell me where should I include this: CI = false
Brody
Brody2y ago
you dont want to fix the warnings? fixing the warnings is the right thing to do
Nicolás Bonder
Nicolás BonderOP2y ago
oh ok, I will try that
Brody
Brody2y ago
you can set CI = false in the railway service variables for now, but defiantly work on fixing the warnings later
Nicolás Bonder
Nicolás BonderOP2y ago
No, I removed the warnings.
Brody
Brody2y ago
thats what i like to hear
Nicolás Bonder
Nicolás BonderOP2y ago
Now the front is working, but I stull have problems with the backend. I will see what I can do and if cant solve it I come back Thanks!
Brody
Brody2y ago
what problems are you having with the backend, id be happy to help where i can
Nicolás Bonder
Nicolás BonderOP2y ago
In the console I see: Uncaught (in promise) TypeError: Failed to fetch at actions.js:25:16 at Object.dispatch (index.js:16:18) at dispatch (<anonymous>:1:55424) at Pokemons.js:51:5 at zs (react-dom.production.min.js:262:359) at t.unstable_runWithPriority (scheduler.production.min.js:18:343) at Ko (react-dom.production.min.js:122:325) at Ds (react-dom.production.min.js:261:308) at react-dom.production.min.js:261:215 at B (scheduler.production.min.js:16:224) And any pokemon is loading
Brody
Brody2y ago
what status code do you see for that failed request in the network tab?
Nicolás Bonder
Nicolás BonderOP2y ago
Sorry, I just come back, I dont know you if you are still there. The status is 200
Nicolás Bonder
Nicolás BonderOP2y ago
Brody
Brody2y ago
well 200 is a good number show a screenshot of the entire console logs?
Nicolás Bonder
Nicolás BonderOP2y ago
Brody
Brody2y ago
you are trying to make requests over http, you need to make requests with https
Nicolás Bonder
Nicolás BonderOP2y ago
Ok, I will check what do I need to change I changed that, but now I have a CORS error: Access to fetch at 'https://pokemonback.up.railway.app/pokemons' from origin 'https://pokemonfront.up.railway.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. I added CORS
Nicolás Bonder
Nicolás BonderOP2y ago
Nicolás Bonder
Nicolás BonderOP2y ago
And I still have the same error
Brody
Brody2y ago
Nicolás Bonder
Nicolás BonderOP2y ago
ok, that helps with the cors problem?
Brody
Brody2y ago
i mean your current issue isnt cors your app isnt responding
Nicolás Bonder
Nicolás BonderOP2y ago
I changed as you show, and I corrected other things, but I still cant fix it
Nicolás Bonder
Nicolás BonderOP2y ago
Brody
Brody2y ago
show me what you have changed in your backend code
Nicolás Bonder
Nicolás BonderOP2y ago
this is app.js: const express = require('express'); const cookieParser = require('cookie-parser'); const bodyParser = require('body-parser'); const morgan = require('morgan'); const routes = require('./routes/index.js'); const cors = require('cors'); require('./db.js'); const server = express(); server.name = 'API'; server.use(bodyParser.urlencoded({ extended: true, limit: '50mb' })); server.use(bodyParser.json({ limit: '50mb' })); server.use(cookieParser()); server.use(morgan('dev')); server.use(express.json()); // Habilitar CORS server.use(cors()); server.use((req, res, next) => { //res.header('Access-Control-Allow-Origin', 'http://localhost:3000'); // update to match the domain you will make the request from //Testing deploy in Railway res.header('Access-Control-Allow-Origin', 'https://pokemonfront.up.railway.app'); res.header('Access-Control-Allow-Credentials', 'true'); res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE'); next(); }); server.get("/", (req, res) => { res.json({ info: "Page uploaded successfully." }); }); server.use('/', routes); // Error catching endware. server.use((err, req, res, next) => { // eslint-disable-line no-unused-vars const status = err.status 500; const message = err.message err; console.error(err); res.status(status).send(message); }); module.exports = server;
Brody
Brody2y ago
show me the package.json please
Nicolás Bonder
Nicolás BonderOP2y ago
{ "name": "api", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "node index.js", "test": "mocha -w ./tests/*/.spec.js" }, "author": "Henry", "license": "ISC", "engines": { "node": ">=12.18.3", "npm": ">=6.14.6" }, "dependencies": { "axios": "^1.1.3", "body-parser": "^1.19.0", "cookie-parser": "^1.4.5", "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", "morgan": "^1.10.0", "node-fetch": "^2.6.7", "pg": "^8.8.0", "sequelize": "^6.3.5" }, "devDependencies": { "chai": "^4.2.0", "mocha": "^8.2.1", "nodemon": "^2.0.6", "supertest": "^6.0.1", "supertest-session": "^4.1.0" } }
Brody
Brody2y ago
please enclose any code with triple back ticks
Nicolás Bonder
Nicolás BonderOP2y ago
I am not pretty sure what do you mean
Brody
Brody2y ago
this is a back tick ` anyway
Nicolás Bonder
Nicolás BonderOP2y ago
yes, I understand...it is as stack overflow... I have to put
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "mocha -w ./tests/**/*.spec.js"
},
"author": "Henry",
"license": "ISC",
"engines": {
"node": ">=12.18.3",
"npm": ">=6.14.6"
},
"dependencies": {
"axios": "^1.1.3",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"morgan": "^1.10.0",
"node-fetch": "^2.6.7",
"pg": "^8.8.0",
"sequelize": "^6.3.5"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.2.1",
"nodemon": "^2.0.6",
"supertest": "^6.0.1",
"supertest-session": "^4.1.0"
}
}
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "mocha -w ./tests/**/*.spec.js"
},
"author": "Henry",
"license": "ISC",
"engines": {
"node": ">=12.18.3",
"npm": ">=6.14.6"
},
"dependencies": {
"axios": "^1.1.3",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"morgan": "^1.10.0",
"node-fetch": "^2.6.7",
"pg": "^8.8.0",
"sequelize": "^6.3.5"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.2.1",
"nodemon": "^2.0.6",
"supertest": "^6.0.1",
"supertest-session": "^4.1.0"
}
}
Brody
Brody2y ago
show me your index.js file please
Nicolás Bonder
Nicolás BonderOP2y ago
const server = require('./src/app.js');
const { conn } = require('./src/db.js');

const port = process.env.PORT || 3000;

// Syncing all the models at once.
conn.sync({ force: true }).then(() => {
server.listen(port, "0.0.0.0", () => {
console.log('%s listening at 3001'); // eslint-disable-line no-console
});
});

const server = require('./src/app.js');
const { conn } = require('./src/db.js');

const port = process.env.PORT || 3000;

// Syncing all the models at once.
conn.sync({ force: true }).then(() => {
server.listen(port, "0.0.0.0", () => {
console.log('%s listening at 3001'); // eslint-disable-line no-console
});
});

Brody
Brody2y ago
what's conn.sync do you have a repo for your backend too?
Nicolás Bonder
Nicolás BonderOP2y ago
GitHub
GitHub - nicobonder/pokemonBack: Backend to create Pokemon App
Backend to create Pokemon App. Contribute to nicobonder/pokemonBack development by creating an account on GitHub.
Brody
Brody2y ago
and bad timing, I was called for dinner, I'll get back to you later but if I had to guess, your code is not connecting to the database
Nicolás Bonder
Nicolás BonderOP2y ago
I must be honest, that file already was done. It was a repor that I receibed to do a project when I was doing a bootcamp and I dont remember what was that line.
Brody
Brody2y ago
interesting, well I'll look into your code after dinner
Nicolás Bonder
Nicolás BonderOP2y ago
Dont worry, I also have to go. Thanks for everything. Tomorrow we can follow or if I can I connect again
Brody
Brody2y ago
okay I'll look later either way so here you are trying to connect to postgres https://github.com/nicobonder/pokemonBack/blob/main/src/db.js#L9 but those are not the standard postgres variables names, the correct variable names are stated here https://docs.railway.app/databases/postgresql#connect so make sure you have a postgres database in the same railway project setup the variable references using the standard names, in your railway backend service variables https://docs.railway.app/develop/variables#reference-variables
Nicolás Bonder
Nicolás BonderOP2y ago
Hi, do you mean to this:
${DB_USER}:${DB_PASSWORD}@${DB_HOST}
${DB_USER}:${DB_PASSWORD}@${DB_HOST}
Those are the name I used in the .env Do you think it is better if I use the name suggested in the guide you sent me?
Brody
Brody2y ago
you should just be able to use railways DATABASE_URL for simplicity, there's no need to build your own connection string like you currently do
Nicolás Bonder
Nicolás BonderOP2y ago
I dont understand. I need to do all that to connect the DB when I was working in localhost. I added all the enviroment variables in railway, there I have a DATABASE_URL, but I dont know how to use it in my code. Should I replace:
const sequelize = new Sequelize(`postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}/pokemon`
const sequelize = new Sequelize(`postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}/pokemon`
for:
const sequelize = new Sequelize(DATABASE_URL, {
const sequelize = new Sequelize(DATABASE_URL, {
Brody
Brody2y ago
it would be process.env.DATABASE_URL
Nicolás Bonder
Nicolás BonderOP2y ago
Ok so I will use this connection:
const sequelize = new Sequelize(process.env.DATABASE_URL, {
logging: false, // set to console.log to see the raw SQL queries
native: false, // lets Sequelize know we can use pg-native for ~30% more speed
});
const sequelize = new Sequelize(process.env.DATABASE_URL, {
logging: false, // set to console.log to see the raw SQL queries
native: false, // lets Sequelize know we can use pg-native for ~30% more speed
});
Brody
Brody2y ago
looks about right show me a screenshot of your service variables?
Nicolás Bonder
Nicolás BonderOP2y ago
Brody
Brody2y ago
thats the plugin, show me a screenshot of your railway service variables
Nicolás Bonder
Nicolás BonderOP2y ago
Sorry, what do you mean with service variables?
Brody
Brody2y ago
the railway service show me a screenshot of the variables tab
Nicolás Bonder
Nicolás BonderOP2y ago
Brody
Brody2y ago
delete those, and then setup the variables properly
Nicolás Bonder
Nicolás BonderOP2y ago
ok
Nicolás Bonder
Nicolás BonderOP2y ago
Finally it loading the pokemons. Now I just have to check in my code why if I filter to get the pokemons created in DB doesnt show it and go back to show all the pokes.
Nicolás Bonder
Nicolás BonderOP2y ago
I still have job to do Thank you!
Brody
Brody2y ago
no problem!
Want results from more Discord servers?
Add your server