Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign Build Deployment Process (External) #113

Merged
merged 90 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
27a21ee
Create image_build_push.yml
MukuFlash03 Mar 18, 2024
8b6c914
Corrected Dockerfile path
Mar 18, 2024
9fa5ead
Added Dockerfile in repo root.
Mar 20, 2024
e2b4117
Merge branch 'image-push-merge' into image-push
MukuFlash03 Mar 20, 2024
4bbdb85
Merge pull request #2 from MukuFlash03/image-push
MukuFlash03 Mar 20, 2024
0345490
Replaced config.py with config-fake.py in external Dockerfile.
Mar 20, 2024
aad1fd6
Merge pull request #3 from MukuFlash03/image-push
MukuFlash03 Mar 20, 2024
7617a53
Copy config-fake.py as config.py
Mar 20, 2024
3c6b613
Merge pull request #4 from MukuFlash03/image-push
MukuFlash03 Mar 20, 2024
8425f6e
Removed expose port duplication
Mar 20, 2024
29ab767
Merge pull request #5 from MukuFlash03/image-push
MukuFlash03 Mar 20, 2024
a24bd99
Multiple changes for external repo differences
Mar 25, 2024
54fec6b
Merge pull request #6 from MukuFlash03/image-push
MukuFlash03 Mar 25, 2024
bda1902
Added TODO to change image push branch
Mar 26, 2024
546b072
Merge pull request #7 from MukuFlash03/image-push
MukuFlash03 Mar 26, 2024
3064af6
Removed printing Docker username
Mar 26, 2024
3e59949
Merge pull request #8 from MukuFlash03/image-push
MukuFlash03 Mar 26, 2024
9900c0a
Replacing CognitoConfig class with ENV variables
Mar 29, 2024
9fbbf1a
Merge pull request #9 from MukuFlash03/image-push
MukuFlash03 Mar 29, 2024
8c2038e
Replaced dictionary in config.py
Mar 29, 2024
3053bab
Merge pull request #10 from MukuFlash03/image-push
MukuFlash03 Mar 29, 2024
2580fd1
Removing ENV variables from Dockerfile
Apr 2, 2024
6a85960
Merge pull request #11 from MukuFlash03/image-push
MukuFlash03 Apr 2, 2024
ba77b5c
Update requirements.txt
MukuFlash03 Apr 5, 2024
a709d49
Removed sed / jq usage from start scripts
Apr 12, 2024
4da6bb9
Merge pull request #12 from MukuFlash03/image-push
MukuFlash03 Apr 12, 2024
8446e3c
Changing base image to build from redesign server image
Apr 12, 2024
a9e46a6
Bumped up base server image tag
Apr 16, 2024
beeab8f
Merge branch 'image-push-merge' into image-push
MukuFlash03 Apr 16, 2024
fc792bc
Merge pull request #13 from MukuFlash03/image-push
MukuFlash03 Apr 16, 2024
5861171
Bump up base server image tag
Apr 16, 2024
f924af0
Merge pull request #14 from MukuFlash03/image-push
MukuFlash03 Apr 16, 2024
237df16
Artifact download test - 1
Apr 26, 2024
ab51504
Bumped up server image tag
Apr 30, 2024
cd9682a
Artifact + Matrix - 1
May 1, 2024
11dd97b
Artifact + Matrix - 2
May 1, 2024
ed3a505
Artifact + Matrix - 3
May 1, 2024
d66893b
Artifact + Matrix - 4
May 2, 2024
39b289f
Artifact + Matrix - 5
May 2, 2024
340d9d0
Artifact + Matrix - 6
May 2, 2024
15c9da1
Artifact + Matrix - 7
May 2, 2024
0c78ad3
Artifact + Matrix - 8
May 2, 2024
d03ce01
Artifact + Matrix - 9
May 3, 2024
a2eca04
Updated docker image tag in .env to the latest timestamp:
actions-user May 3, 2024
3b8f312
Updated docker image tag in .env to the latest timestamp: 2024-05-03-…
actions-user May 3, 2024
352c8ae
Added TODOs in github actions workflow YAML file.
May 3, 2024
d98f75c
Artifact + Matrix - 10
May 3, 2024
f1ea34c
Updated docker image tag in .env file to the latest timestamp
actions-user May 3, 2024
629831f
Updated docker image tag in .env file to the latest timestamp
actions-user May 3, 2024
43adc05
Merge branch 'image-push' into tags-combo-approach
nataliejschultz May 6, 2024
5e0de4b
Updated docker image tag in .env file to the latest timestamp
actions-user May 6, 2024
791b6d9
Update Dockerfile
nataliejschultz May 6, 2024
4a90d2b
Syntax
nataliejschultz May 6, 2024
53dddcf
Updated docker image tag in .env file to the latest timestamp
actions-user May 6, 2024
e56b1e1
Update Dockerfile again
nataliejschultz May 7, 2024
980877f
Finalize Dockerfiile
nataliejschultz May 7, 2024
f1fd42c
Update Dockerfile in docker folder
nataliejschultz May 7, 2024
9f96044
Merge pull request #15 from MukuFlash03/tags-combo-approach
nataliejschultz May 7, 2024
cb502af
Update fetch_runID.py
nataliejschultz May 7, 2024
0d4a2a3
Cleanup image_build_push.yml
nataliejschultz May 8, 2024
f91fcb1
Removing docker build, updating DOCKER_IMAGE_TAG --> SERVER IMAGE TAG…
nataliejschultz May 26, 2024
8cb70f5
Reverting for testing
nataliejschultz May 26, 2024
1bd8e33
Trying to trigger run without matrix
nataliejschultz May 26, 2024
7c82601
Changing repo name
nataliejschultz May 26, 2024
da904e5
Updated docker image tag in .env file to the latest timestamp
actions-user May 26, 2024
b59fd01
So close to trying docker compose with actions
nataliejschultz May 26, 2024
80a5e43
Build context change
nataliejschultz May 26, 2024
1d1cadd
dockerhub repos are case sensitive.
nataliejschultz May 26, 2024
b551740
Updating tag
nataliejschultz May 26, 2024
f14b38a
Rename docker tag
nataliejschultz May 26, 2024
f7f9319
Add artifact
nataliejschultz May 26, 2024
ada5613
Trying to use admin dash tag
nataliejschultz May 26, 2024
e061cd9
Reverting changes
nataliejschultz May 26, 2024
c3849ad
Remove extra dockerfile
nataliejschultz May 26, 2024
a63e8a2
Merge branch 'master' into image-push
nataliejschultz May 26, 2024
59fd7dc
server image tag update
nataliejschultz May 26, 2024
ddf6dc3
Update .env
nataliejschultz May 26, 2024
a937601
Update image_build_push.yml
nataliejschultz May 26, 2024
e26216a
Update start.sh
nataliejschultz May 28, 2024
24689c5
Switching to build prod compose
nataliejschultz May 28, 2024
27541a7
Updated username to clarify that env file is being updated
Aug 14, 2024
85b2384
Modified tag variable names to be more relevant
Aug 14, 2024
1e6ef8f
Removing redundant pip install
Aug 14, 2024
599d991
Certificates added in Dockerfile
Aug 14, 2024
67a88b3
Fixed indentation
Aug 14, 2024
3f66ef3
Added .env.cognito.template + Removed cognito variables from .env and…
Aug 14, 2024
5098e07
Removing artifact method
Aug 14, 2024
5eff0be
Updating latest server image tag
Aug 14, 2024
efccd5a
Merge branch 'master' into image-push
MukuFlash03 Aug 14, 2024
48f6ca9
Moving .env file update and git commit to the end
Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SERVER_IMAGE_TAG=2024-08-12--15-15
7 changes: 7 additions & 0 deletions .env.cognito.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
COGNITO_CLIENT_ID=''
COGNITO_CLIENT_SECRET=''
COGNITO_REDIRECT_URL=''
COGNITO_TOKEN_ENDPOINT=''
COGNITO_USER_POOL_ID=''
COGNITO_REGION=''
COGNITO_AUTH_URL=''
98 changes: 98 additions & 0 deletions .github/workflows/image_build_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: docker-image-push-admin

on:
push:
branches: [ master ]

workflow_dispatch:
inputs:
docker_image_tag:
description: "Latest Docker image tags passed from e-mission-server repository on image build and push"
required: true

env:
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}

jobs:
build:
runs-on: ubuntu-latest

env:
DOCKER_TAG_FROM_WORKFLOW_DISPATCH: ${{ github.event.inputs.docker_image_tag }}

steps:
- uses: actions/checkout@v4

- name: Set docker image tag from .env file
run: |
set -a; source .env; set +a
echo "DOCKER_TAG_FROM_PUSH=${SERVER_IMAGE_TAG}" >> $GITHUB_ENV

- name: Print input docker image tag
run: |
echo "Event name: ${{ github.event_name }}"
echo "Latest docker image tag (push): ${{ env.DOCKER_TAG_FROM_PUSH }}"
echo "Latest docker image tag (workflow_dispatch): ${{ env.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}"

- name: docker login
run: | # log into docker hub account
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD

- name: Get current date # get the date of the build
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d--%M-%S')"

- name: Run a one-line script
run: echo running in repo ${GITHUB_REPOSITORY#*/} branch ${GITHUB_REF##*/} on ${{ steps.date.outputs.date }}

- name: build docker image
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_WORKFLOW_DISPATCH docker compose -f docker-compose-prod.yml build
else
SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_PUSH docker compose -f docker-compose-prod.yml build
fi
docker images

- name: rename docker image
run: |
docker image tag e-mission/opdash:0.0.1 $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }}

- name: push docker image
run: |
docker push $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }}

- name: Update .env file
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "Workflow_dispatch: New server image built and pushed, Updating image tag in .env"
echo "SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_WORKFLOW_DISPATCH" > .env
else
echo "Push event: Restoring latest server image tag from .env"
fi

- name: Add, Commit, Push changes to .env file
run: |
git config --local user.email "[email protected]"
git config --local user.name "Github Actions bot to update .env with latest tags"
if git diff --quiet; then
echo "Latest timestamp already present in .env file, no changes to commit"
else
git add .env
git commit -m "Updated docker image tag in .env file to the latest timestamp"
git push origin
fi

- name: Create artifact text file
run: |
echo ${{ steps.date.outputs.date }} > admin_dash_tag_file.txt
echo "Created tag text file"

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: admin-dash-image-tag
path: admin_dash_tag_file.txt
overwrite: true

12 changes: 8 additions & 4 deletions app_sidebar_collapsible.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from dash import Input, Output, dcc, html, Dash
import dash_auth
import logging
import base64
# Set the logging right at the top to make sure that debug
# logs are displayed in dev mode
# until https://github.com/plotly/dash/issues/532 is fixed
Expand All @@ -29,15 +30,17 @@
import flask_talisman as flt



OPENPATH_LOGO = "https://www.nrel.gov/transportation/assets/images/openpath-logo.jpg"
OPENPATH_LOGO = os.path.join(os.getcwd(), "assets/openpath-logo.jpg")
encoded_image = base64.b64encode(open(OPENPATH_LOGO, 'rb').read()).decode("utf-8")
shankari marked this conversation as resolved.
Show resolved Hide resolved
auth_type = os.getenv('AUTH_TYPE')


if auth_type == 'cognito':
from utils.cognito_utils import authenticate_user, get_cognito_login_page
elif auth_type == 'basic':
from config import VALID_USERNAME_PASSWORD_PAIRS
VALID_USERNAME_PASSWORD_PAIRS = {
'hello': 'world'
}

app = Dash(
external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.FONT_AWESOME],
Expand All @@ -59,7 +62,8 @@
[
# width: 3rem ensures the logo is the exact width of the
# collapsed sidebar (accounting for padding)
html.Img(src=OPENPATH_LOGO, style={"width": "3rem"}),
# html.Img(src=OPENPATH_LOGO, style={"width": "3rem"}),
html.Img(src=f"data:image/png;base64,{encoded_image}", style={"width": "3rem"}), # Working
html.H2("OpenPATH"),
],
className="sidebar-header",
Expand Down
Binary file added assets/openpath-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 0 additions & 21 deletions config-fake.py

This file was deleted.

2 changes: 2 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
build:
context: .
dockerfile: docker/Dockerfile
args:
SERVER_IMAGE_TAG: ${SERVER_IMAGE_TAG}
image: e-mission/opdash:0.0.1
ports:
- "8050:8050"
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-prod-nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ services:
build:
context: .
dockerfile: docker/Dockerfile
args:
SERVER_IMAGE_TAG: ${SERVER_IMAGE_TAG}
image: e-mission/opdash:0.0.1
environment:
DASH_DEBUG_MODE: "True"
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
build:
context: .
dockerfile: docker/Dockerfile
args:
SERVER_IMAGE_TAG: ${SERVER_IMAGE_TAG}
image: e-mission/opdash:0.0.1
ports:
- "8050:8050"
Expand Down
10 changes: 7 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
FROM shankari/e-mission-server:master_2024-07-19--34-43
ARG SERVER_IMAGE_TAG

FROM shankari/e-mission-server:master_${SERVER_IMAGE_TAG}

ADD https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem /etc/ssl/certs/

ENV DASH_DEBUG_MODE True
ENV SERVER_PORT 8050
Expand All @@ -17,10 +21,10 @@ COPY ./pages ./
WORKDIR /usr/src/app/utils
COPY ./utils ./
WORKDIR /usr/src/app
COPY app.py config.py app_sidebar_collapsible.py assets globals.py globalsUpdater.py Procfile ./
COPY app.py app_sidebar_collapsible.py globals.py globalsUpdater.py Procfile ./

WORKDIR /usr/src/app/assets
COPY assets/style.css ./
COPY assets/ ./
shankari marked this conversation as resolved.
Show resolved Hide resolved
RUN mkdir qrcodes

# copy over test data
Expand Down
8 changes: 1 addition & 7 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
source setup/activate.sh

# change the db host
echo "DB host = "${DB_HOST}
if [ -z ${DB_HOST} ] ; then
local_host=`hostname -i`
sed "s_localhost_${local_host}_" conf/storage/db.conf.sample > conf/storage/db.conf
else
sed "s_localhost_${DB_HOST}_" conf/storage/db.conf.sample > conf/storage/db.conf
fi
echo ${DB_HOST}

# run the app
# python app.py
Expand Down
12 changes: 6 additions & 6 deletions utils/cognito_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import flask
import requests
import dash
import os

from config import CognitoConfig
from utils import decode_jwt


def get_tokens(code):
client_id = CognitoConfig.CLIENT_ID
client_secret = CognitoConfig.CLIENT_SECRET
redirect_uri = CognitoConfig.REDIRECT_URL
token_endpoint = CognitoConfig.TOKEN_ENDPOINT
client_id = os.getenv("COGNITO_CLIENT_ID", '')
client_secret = os.getenv("COGNITO_CLIENT_SECRET", '')
redirect_uri = os.getenv("COGNITO_REDIRECT_URL", '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add a list of environment variables required in the readme?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or create a .env file as a template?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.env file added

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .env does not have the full list of environment variables

token_endpoint = os.getenv("COGNITO_TOKEN_ENDPOINT", '')

encoded_data = base64.b64encode(f'{client_id}:{client_secret}'.encode('ascii')).decode('ascii')
headers = {
Expand Down Expand Up @@ -59,7 +59,7 @@ def get_cognito_login_page(text='Welcome to the dashboard', color='black'):
dash.html.Label(text, style={
'font-size': '15px', 'display': 'block', 'verticalAlign': 'top', 'padding': '15px', 'color': color
}),
dbc.Button('Login with AWS Cognito', id='login-button', href=CognitoConfig.AUTH_URL, style={
dbc.Button('Login with AWS Cognito', id='login-button', href=os.getenv("COGNITO_AUTH_URL", ''), style={
'font-size': '14px', 'display': 'block', 'padding': '15px', 'verticalAlign': 'top',
'background-color': 'green', 'color': 'white'
}),
Expand Down
15 changes: 7 additions & 8 deletions utils/decode_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import urllib.request
from jose import jwk, jwt
from jose.utils import base64url_decode
import os

from config import CognitoConfig

client_id = CognitoConfig.CLIENT_ID
client_secret = CognitoConfig.CLIENT_SECRET
redirect_uri = CognitoConfig.REDIRECT_URL
token_endpoint = CognitoConfig.TOKEN_ENDPOINT
user_pool_id = CognitoConfig.USER_POOL_ID
region = CognitoConfig.REGION
client_id = os.getenv("COGNITO_CLIENT_ID", '')
client_secret = os.getenv("COGNITO_CLIENT_SECRET", '')
redirect_uri = os.getenv("COGNITO_REDIRECT_URL", '')
token_endpoint = os.getenv("COGNITO_TOKEN_ENDPOINT", '')
user_pool_id = os.getenv("COGNITO_USER_POOL_ID", '')
region = os.getenv("COGNITO_REGION", '')

keys_url = f'https://cognito-idp.{region}.amazonaws.com/{user_pool_id}/.well-known/jwks.json'
# instead of re-downloading the public keys every time
Expand Down