From 2b63c56a2f494b6d731d68a75fa42b6fced120c6 Mon Sep 17 00:00:00 2001 From: KBA07 Date: Wed, 31 May 2023 11:46:18 +0530 Subject: [PATCH] enabling github actions --- .github/workflows/deploy.yml | 59 ++++++++++++++++++++++++++++++++++++ Dockerfile | 12 ++++++++ app.py | 2 +- deploy.sh | 20 ++++++++++++ requirements.txt | 2 ++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile create mode 100644 deploy.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..dc81088 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,59 @@ +name: alhazenlabs-ec2-deployment + +on: + push: + branches: [main] + +jobs: + start: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: AWS SSM Send-Command + uses: peterkimzz/aws-ssm-send-command@master + id: ssm + with: + aws-region: ${{ secrets.AWS_REGION }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + instance-ids: ${{ secrets.INSTANCE_ID }} + + working-directory: /home/ubuntu/deployment + command: /bin/sh ./deploy.sh + + # Catch SSM outputs + # - name: Get the outputs + # run: echo "The Command id is ${{ steps.ssm.outputs.command-id }}" + +## Setting up your Domain + +# So far, users can access the site using the Elastic IP. However, it can be difficult to remember and share so we will configure a custom domain name. + +# To get started, you need to first purchase a domain. This can range from $10 to $1,000+s. Amazon has a service called Route53 you can use or you can choose other providers such as [Google Domains](https://domains.google/), [GoDaddy](https://www.godaddy.com/), etc. (we used Google for AlgoAcademy which was $10/year). + +# There are two steps you would need to configure to connect the project with a custom domain: + +# - Create domain records with DNS registrar +# - Configure NGINX on the EC2 instance to recognize the domain + +# --- + +# ### _Creating Domain records_ + +# Let's start with configuring our DNS with records: + +# - Go to the **DNS** portion of your registrar. +# - Find where you can create custom resource records. + +# Set the records like so: + +# | Name | Type | TTL | Data | +# | ---- | :---: | :-: | ----------------------: | +# | @ | A | 1h | YOUR-ELASTIC-IP-ADDRESS | +# | www | CNAME | 1h | your-awesome-site.com | + +# ### _Configuring our Web Server_ + +# Edit the NGINX config file inside your EC2 instance: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b940f80 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.8.16-slim-bullseye + +ENV API_USER=test API_PASSWORD=test ECWID_PRIVATE_TOKEN=test \ + STORE_ID=123 PICKUP_LOCATION_ID=12324 ID_FIRST_VALUE=1 \ + SENDER_EMAIL=kba0708@gmail.com SENDER_PASSWORD=test + +COPY requirements.txt requirements.txt +RUN pip install -r requirements.txt --no-cache-dir + +COPY . . +EXPOSE 8081 +ENTRYPOINT [ "python", "app.py" ] \ No newline at end of file diff --git a/app.py b/app.py index 8776cd2..c57344c 100644 --- a/app.py +++ b/app.py @@ -15,4 +15,4 @@ # Here the app.app is the flask app which can be used to add flask app register_flask_blueprint(app.app, False) - app.run(port=8081, debug=True) \ No newline at end of file + app.run(port=8081) \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..20de0e3 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,20 @@ +DOCKER_APT_PACKAGE="docker.io" +IMAGE_NAME="docker.io/alhazenlabs/deployment:v1" +CONTAINER_NAME="alhazenlabs-deployment" +PORT="8081" + +if [ $(dpkg-query -W -f='${Status}' $DOCKER_APT_PACKAGE 2>/dev/null | grep -c "ok installed") -eq 0 ]; +then + echo "Installation of docker wasn't found installing docker..." + sudo apt-get update + sudo apt install $DOCKER_APT_PACKAGE + sudo groupadd docker + sudo usermod -aG docker $USER +else + echo "Installation of docker found skipping installation" +fi + +echo "stopping the existing container: $CONTAINER_NAME" +docker stop $CONTAINER_NAME +echo "starting a new container: $CONTAINER_NAME" +docker run --name $CONTAINER_NAME -p 80:8081 -p 443:8081 -d $IMAGE_NAME diff --git a/requirements.txt b/requirements.txt index 903ba69..862c30b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ +# Python 3.8.10 + APScheduler==3.0.0 asgiref==3.7.2 attrs==23.1.0