-
Notifications
You must be signed in to change notification settings - Fork 11
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
Changes from 60 commits
27a21ee
8b6c914
9fa5ead
e2b4117
4bbdb85
0345490
aad1fd6
7617a53
3c6b613
8425f6e
29ab767
a24bd99
54fec6b
bda1902
546b072
3064af6
3e59949
9900c0a
9fbbf1a
8c2038e
3053bab
2580fd1
6a85960
ba77b5c
a709d49
4da6bb9
8446e3c
a9e46a6
beeab8f
fc792bc
5861171
f924af0
237df16
ab51504
cd9682a
11dd97b
ed3a505
d66893b
39b289f
340d9d0
15c9da1
0c78ad3
d03ce01
a2eca04
3b8f312
352c8ae
d98f75c
f1ea34c
629831f
43adc05
5e0de4b
791b6d9
4a90d2b
53dddcf
e56b1e1
980877f
f1fd42c
9f96044
cb502af
0d4a2a3
f91fcb1
8cb70f5
1bd8e33
7c82601
da904e5
b59fd01
80a5e43
1d1cadd
b551740
f14b38a
f7f9319
ada5613
e061cd9
c3849ad
a63e8a2
59fd7dc
ddf6dc3
a937601
e26216a
24689c5
27541a7
85b2384
1e6ef8f
599d991
67a88b3
3f66ef3
5098e07
5eff0be
efccd5a
48f6ca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DOCKER_IMAGE_TAG=2024-05-03--42-05 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
import json | ||
import logging | ||
import requests | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
''' | ||
Workflow "docker image" uses image_build_push.yml | ||
From above commented out code, and checked via terminal as well, | ||
workflow id for the "docker image" can be fetched using: | ||
https://api.github.com/repos/MukuFlash03/e-mission-server/actions/workflows | ||
https://api.github.com/repos/e-mission/e-mission-server/actions/workflows | ||
|
||
For MukuFlash03: id = 75506902 | ||
For e-mission-server: id = 35580278 | ||
''' | ||
|
||
download_url = "https://api.github.com/repos/e-mission/e-mission-server/actions/workflows/35580278/runs" | ||
logging.debug("About to fetch workflow runs present in docker image workflow present in e-mission-server from %s" % download_url) | ||
r = requests.get(download_url) | ||
if r.status_code != 200: | ||
logging.debug(f"Unable to fetch workflow runs, status code: {r.status_code}") | ||
sys.exit(1) | ||
else: | ||
workflow_runs_json = json.loads(r.text) | ||
logging.debug(f"Successfully fetched workflow runs") | ||
|
||
workflow_runs = workflow_runs_json["workflow_runs"] | ||
if workflow_runs: | ||
successful_runs = [run for run in workflow_runs \ | ||
if run["status"] == "completed" and \ | ||
run["conclusion"] == "success" and \ | ||
run["head_branch"] == "master" | ||
] | ||
if successful_runs: | ||
sorted_runs = successful_runs.sort(reverse=True, key=lambda x: x["updated_at"]) | ||
sorted_runs = sorted(successful_runs, reverse=True, key=lambda x: x["updated_at"]) | ||
# print(sorted_runs) | ||
latest_run_id = sorted_runs[0]["id"] | ||
print(f"::set-output name=run_id::{latest_run_id}") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
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: | ||
fetch_run_id: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
run_id: ${{ steps.get_run_id.outputs.run_id }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install requests | ||
|
||
- name: Run Python script | ||
id: run_script | ||
run: | | ||
echo "Fetching latest successful run ID from e-misison-server docker image workflow" | ||
python .github/fetch_runID.py | ||
|
||
- name: Get Run ID | ||
id: get_run_id | ||
run: echo "run_id=${{ steps.run_script.outputs.run_id }}" >> "$GITHUB_OUTPUT" | ||
|
||
fetch_tag: | ||
needs: fetch_run_id | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
RUN_ID: ${{ needs.fetch_run_id.outputs.run_id }} | ||
|
||
outputs: | ||
docker_image_tag: ${{ steps.get_docker_tag.outputs.docker_image_tag }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Run ID from previous fetch_run_id job | ||
run: echo Run ID from previous job ${{ env.RUN_ID }} | ||
|
||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: docker-image-tag | ||
# TODO: Create a token with basic repo permissions | ||
github-token: ${{ secrets.GH_PAT_TAG }} | ||
repository: e-mission/e-mission-server | ||
run-id: ${{ env.RUN_ID }} | ||
|
||
- name: Print artifact tag | ||
id: get_docker_tag | ||
run: | | ||
cat tag_file.txt | ||
docker_image_tag=$(cat tag_file.txt) | ||
echo $docker_image_tag | ||
echo "docker_image_tag=$(echo $docker_image_tag)" >> $GITHUB_OUTPUT | ||
|
||
build: | ||
needs: fetch_tag | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
DOCKER_IMAGE_TAG_1: ${{ needs.fetch_tag.outputs.docker_image_tag }} | ||
DOCKER_IMAGE_TAG_2: ${{ github.event.inputs.docker_image_tag }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Print input docker image tag | ||
run: | | ||
echo "Event name: ${{ github.event_name }}" | ||
echo "Latest docker image tag (push): ${{ env.DOCKER_IMAGE_TAG_1 }}" | ||
echo "Latest docker image tag (workflow_dispatch): ${{ env.DOCKER_IMAGE_TAG_2 }}" | ||
|
||
- 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 "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG_2" > .env | ||
else | ||
echo "Push event: Restoring latest server image tag in .env" | ||
echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG_1" > .env | ||
fi | ||
|
||
- name: Add, Commit, Push changes to .env file | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
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: 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 | ||
docker build --build-arg DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG_2 -t $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} . | ||
else | ||
docker build --build-arg DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG_1 -t $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} . | ||
fi | ||
docker images | ||
|
||
- name: push docker image | ||
run: | | ||
docker push $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this file? There is already a Dockerfile at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was from here, but since we're using docker compose which builds a different Dockerfile, it can be removed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
ARG DOCKER_IMAGE_TAG | ||
|
||
FROM shankari/e-mission-server:master_${DOCKER_IMAGE_TAG} | ||
|
||
ENV DASH_DEBUG_MODE True | ||
ENV SERVER_PORT 8050 | ||
|
||
# copy over setup files | ||
WORKDIR /usr/src/app/dashboard_setup | ||
COPY requirements.txt nrel_dash_components-0.0.1.tar.gz docker/setup.sh ./ | ||
|
||
# install requirements.txt | ||
WORKDIR /usr/src/app | ||
RUN bash -c "./dashboard_setup/setup.sh" | ||
|
||
# copy over dashboard code | ||
WORKDIR /usr/src/app/pages | ||
COPY ./pages ./ | ||
WORKDIR /usr/src/app/utils | ||
COPY ./utils ./ | ||
WORKDIR /usr/src/app | ||
COPY app.py app_sidebar_collapsible.py globals.py globalsUpdater.py Procfile ./ | ||
|
||
WORKDIR /usr/src/app/assets | ||
COPY assets/ ./ | ||
RUN mkdir qrcodes | ||
|
||
# copy over test data | ||
WORKDIR /usr/src/app/data | ||
COPY data ./ | ||
|
||
# open listening port, this may be overridden in docker-compose file | ||
EXPOSE ${SERVER_PORT} | ||
|
||
# run the dashboard | ||
WORKDIR /usr/src/app/dashboard_setup | ||
COPY docker/start.sh ./ | ||
WORKDIR /usr/src/app | ||
CMD ["/bin/bash", "/usr/src/app/dashboard_setup/start.sh"] |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,8 @@ source setup/activate.sh | |
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 | ||
export DB_HOST=$local_host | ||
echo "Setting db host environment variable to localhost" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be changed to be consistent with the start script changes in the server. |
||
fi | ||
|
||
# run the app | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are these changes needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to match with main repo |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or create a .env file as a template? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .env file added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
token_endpoint = os.getenv("COGNITO_TOKEN_ENDPOINT", '') | ||
|
||
encoded_data = base64.b64encode(f'{client_id}:{client_secret}'.encode('ascii')).decode('ascii') | ||
headers = { | ||
|
@@ -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' | ||
}), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: make name more meaningful.