Last active
June 10, 2016 19:35
-
-
Save jradesenv/527f6e59ab2e7985c38fbed3a2084c83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "INSTALANDO DEPENDENCIAS NPM..." | |
npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ChangeBindAddress () | |
{ | |
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf | |
} | |
StartMySQL () | |
{ | |
ChangeBindAddress | |
/usr/bin/mysqld_safe --port=${DB_PORT} > /dev/null 2>&1 & | |
# Time out in 1 minute | |
LOOP_LIMIT=13 | |
for (( i=0 ; ; i++ )); do | |
if [ ${i} -eq ${LOOP_LIMIT} ]; then | |
echo "Time out. Error log is shown as below:" | |
tail -n 100 ${LOG} | |
exit 1 | |
fi | |
echo "=> Waiting for confirmation of MySQL service startup, trying ${i}/${LOOP_LIMIT} ..." | |
sleep 5 | |
mysql -uroot -e "status" > /dev/null 2>&1 && break | |
done | |
} | |
CreateMySQLUser() | |
{ | |
StartMySQL | |
PASS=${DB_PASSWORD} | |
mysql -uroot -e "CREATE USER '${DB_USER}'@'%' IDENTIFIED BY '$PASS';" | |
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${DB_USER}'@'%' WITH GRANT OPTION;" | |
mysql -u root -e "CREATE DATABASE ${DB_DATABASE}" | |
mysql -u root ${DB_DATABASE} < ${DUMP_PATH} | |
mysql -u root -e "GRANT SELECT, DELETE, INSERT, UPDATE ON ${DB_DATABASE}.* TO '$DB_USER'@'%'"; | |
mysql -u root -e "flush privileges"; | |
#mysqladmin -uroot shutdown | |
} | |
CreateMySQLUser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constantsHelper.appDb = { | |
host: process.env.DB_HOST ? process.env.DB_HOST : 'localhost', | |
user: process.env.DB_USER ? process.env.DB_USER : 'root', | |
password: process.env.DB_PASSWORD ? process.env.DB_PASSWORD : 'pass', | |
database: process.env.DB_DATABASE ? process.env.DB_DATABASE : 'db', | |
port: process.env.DB_PORT ? process.env.DB_PORT : 5432, | |
socketPath: process.env.DB_SOCKET_PATH ? process.env.DB_SOCKET_PATH : false | |
}; | |
var dbConfig = { | |
client: 'mysql', | |
connection: { | |
user: constantsHelper.appDb.user, | |
password: constantsHelper.appDb.password, | |
database: constantsHelper.appDb.database, | |
charset: 'utf8' | |
} | |
}; | |
if (constantsHelper.appDb.socketPath) { | |
dbConfig.connection.socketPath = constantsHelper.appDb.socketPath; | |
} else { | |
dbConfig.connection.host = constantsHelper.appDb.host; | |
dbConfig.connection.port = constantsHelper.appDb.port; | |
} | |
console.log("dbConfig: ", dbConfig); | |
var db = knex(dbConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:trusty | |
# Install packages | |
ENV DEBIAN_FRONTEND noninteractive | |
RUN apt-get update | |
RUN apt-get -yq install mysql-server | |
RUN apt-get install -y --force-yes curl python g++ make | |
RUN curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - | |
RUN apt-get install -y --force-yes nodejs --fix-missing | |
RUN ln -fs /usr/bin/nodejs /usr/local/bin/node | |
# copy source | |
ADD . / | |
# grant exec | |
RUN chmod 755 ./env/*.sh | |
# Exposed ENV | |
ENV PORT 8080 | |
ENV DB_HOST 127.0.0.1 | |
ENV DB_PORT 3060 | |
ENV DB_USER myuser | |
ENV DB_PASSWORD mypass | |
ENV DB_DATABASE mydb | |
ENV DB_SOCKET_PATH '/var/run/mysqld/mysqld.sock' | |
ENV DUMP_PATH /env/dump.sql | |
EXPOSE 8080 | |
RUN /env/db.sh | |
RUN /env/app.sh | |
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `usuario` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`nome` varchar(500) NOT NULL, | |
`login` varchar(100) NOT NULL, | |
`senha` varchar(500) NOT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; | |
CREATE TABLE `post` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`usuarioId` int(11) NOT NULL, | |
`conteudo` varchar(5000) NOT NULL, | |
`dataCriacao` timestamp NULL DEFAULT CURRENT_TIMESTAMP, | |
PRIMARY KEY (`id`), | |
KEY `fk_post_usuario_idx` (`usuarioId`), | |
CONSTRAINT `fk_post_usuario` FOREIGN KEY (`usuarioId`) REFERENCES `usuario` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION | |
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment