diff --git a/.drone.yml b/.drone.yml index 4a9cc2f..0ba8960 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,7 @@ steps: IMAGENAME: postgres:latest CONTAINERNAME: bigbrotherdb COMMAND: create - # OVERWRITE: false + OVERWRITE: false PRIVATE: true CODEFIRST_CLIENTDRONE_ENV_POSTGRES_ROOT_PASSWORD: from_secret: db_root_password @@ -21,15 +21,37 @@ steps: CODEFIRST_CLIENTDRONE_ENV_POSTGRES_PASSWORD: from_secret: db_password - - name: create-bigbrother-database - image: python:latest - commands: - - cd database/ - - pip install psycopg2 - - python3 db-creation.py - environment: - POSTGRES_USER: - from_secret: db_user - POSTGRES_PASSWORD: - from_secret: db_password - depends_on: [ deploy-container-pgsql ] +# - name: create-bigbrother-database +# image: python:latest +# commands: +# - cd database/ +# - pip install psycopg2 +# - python3 db-creation.py +# environment: +# POSTGRES_USER: +# from_secret: db_user +# POSTGRES_PASSWORD: +# from_secret: db_password +# depends_on: [ deploy-container-pgsql ] + + - name: build-image-webapp + image: plugins/docker + settings: + dockerfile: web/Dockerfile + context: ./ + registry: hub.codefirst.iut.uca.fr + repo: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother + username: + from_secret: SECRET_REGISTRY_USERNAME + password: + from_secret: SECRET_REGISTRY_PASSWORD + +# environment: +# POSTGRES_USER: +# from_secret: db_user +# POSTGRES_PASSWORD: +# from_secret: db_password +# CLIENT_ID: +# from_secret: spotify_client_id +# CLIENT_SECRET: +# from_secret: spotify_client_id diff --git a/common/set-env-var.py b/common/set-env-var.py new file mode 100644 index 0000000..08d1ef6 --- /dev/null +++ b/common/set-env-var.py @@ -0,0 +1,8 @@ +import os + +with open('.env', 'w') as f: + f.write("POSTGRES_USER={}\n".format(os.getenv('POSTGRES_USER'))) + f.write("POSTGRES_PASSWORD={}\n".format(os.getenv('POSTGRES_PASSWORD'))) + f.write("POSTGRES_DATABASE={}\n".format(os.getenv('POSTGRES_DATABASE'))) + f.write("CLIENT_ID={}\n".format(os.getenv('CLIENT_ID'))) + f.write("CLIENT_SECRET={}\n".format(os.getenv('CLIENT_SECRET'))) diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..e7a7e84 --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,23 @@ +FROM node:latest + +# Install Python and pip +RUN apt-get update && \ + apt-get install -y python3 python3-pip && \ + rm -rf /var/lib/apt/lists/* + +# Set working directory inside the container +WORKDIR /usr/src/app + +COPY web/* ./ +COPY common/* ./ + +# Install dependencies +RUN npm install ./web/src +RUN pip3 install os + +# Expose the port the app runs on +EXPOSE 3000 + +# Command to run the application +CMD ["python3", "common/set-env-var.py"] +CMD ["node", "--env-file=common/.env" , "web/src/app.js"] diff --git a/web/src/app.js b/web/src/app.js index 8efba1a..203c9b8 100644 --- a/web/src/app.js +++ b/web/src/app.js @@ -16,10 +16,10 @@ const redirectUri = 'http://localhost:3000/callback'; const scope = 'user-read-private user-read-email user-library-read user-library-modify'; const { Client } = pg const client = new Client({ - user: process.env.DB_USER, - host: 'localhost', - database: 'bigbrother', - password: process.env.DB_PASSWORD, + user: process.env.POSTGRES_USER, + host: 'felixmielcarek-bigbrotherdb', + database: process.env.POSTGRES_DATABASE, + password: process.env.POSTGRES_PASSWORD, port: 5432 }) //#endregion @@ -33,9 +33,9 @@ const app = express() app.use(cookieParser()); app.use(express.static(staticDir)); app.get('/', function (req, res) { - req.cookies['account'] == 'true' + /*req.cookies['account'] == 'true' ? res.sendFile(staticDir + '/home.html') - : res.sendFile(staticDir + '/login.html'); + :*/ res.sendFile(staticDir + '/login.html'); }); app.listen(port, () => { @@ -70,7 +70,7 @@ app.get('/login', function (req, res) { //#region ACCESS TOKEN app.get('/callback', (req, res) => { - res.cookie('account', 'true', { maxAge: 360000 }); + //res.cookie('account', 'true', { maxAge: 360000 }); const code = req.query.code; if(state != req.query.state) {