Add Heroku deploy and frontend/backend deploy scripts

- Added local DB container
- Added scripts to deploy frontend/backend by running the deploy command in the containers
- Installing Docker and Heroku CLI in the dev backend container to be able to build and push the container without installing the CLI on the host
- Building and pushing the production container to the Heroku Container Registry
This commit is contained in:
Norbi Peti 2021-11-15 20:34:45 +01:00
parent 828fd52302
commit c62925daf7
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 43 additions and 3 deletions

View file

@ -1,5 +1,5 @@
# Check out https://hub.docker.com/_/node to select a new base image
FROM node:16-slim
FROM node:16-slim AS development
# Create app directory (with user `node`)
RUN mkdir -p /home/node/app
@ -8,6 +8,22 @@ WORKDIR /home/node/app
EXPOSE 4200
# Install Docker
RUN apt-get update
RUN apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update
RUN apt-get install -y docker-ce docker-ce-cli containerd.io
# Install Heroku CLI
RUN curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
ENTRYPOINT [ "/docker.sh" ]
CMD [ "run" ]

View file

@ -1,8 +1,18 @@
#!/usr/bin/env bash
set -e
if [ "$COMMAND" == "deploy" ]; then
echo TODO
exit 0
echo Building Docker image
docker build -t registry.heroku.com/np-szakdolgozat/web -f Dockerfile-prod .
echo Logging in to Heroku
heroku login
echo Logging in to Container Registry
heroku container:login
echo Pushing image
docker push registry.heroku.com/np-szakdolgozat/web
echo Releasing new version
heroku container:release web -a np-szakdolgozat
exit 0
fi
echo "Installing packages"

5
deploy-backend.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
cd backend || exit
docker-compose build backend
docker-compose run -e COMMAND=deploy -v /var/run/docker.sock:/var/run/docker.sock backend

3
deploy-frontend.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
docker-compose run -e COMMAND=deploy frontend

View file

@ -16,6 +16,12 @@ services:
environment:
- COMMAND=run
- DATABASE_URL=${CLEARDB_DATABASE_URL}
database:
image: mysql:5.6
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=DevelopmentPassword
networks:
default: