Skip to content

Commit

Permalink
Merge pull request #206 from uc-cdis/feat/stata-base-update
Browse files Browse the repository at this point in the history
HP-1776 Feat/stata base update
  • Loading branch information
mfshao authored Jan 6, 2025
2 parents 441ddf1 + f53a1b7 commit 016ffbb
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 136 deletions.
74 changes: 28 additions & 46 deletions .github/workflows/build_push_stata_gen3_licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,41 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
- uses: actions/checkout@v4
- uses: prewk/s3-cp-action@v2
with:
root-reserve-mb: 30000
swap-size-mb: 1024
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
- uses: actions/checkout@v2
- uses: prewk/[email protected]
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE: 's3://ctds-stata/Stata17Linux64.tar.gz'
DEST: './jupyter-pystata-gen3-licensed/resources/'
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
source: 's3://ctds-stata/StataNow18Linux64.tar.gz'
dest: './jupyter-pystata-gen3-licensed/resources/'

- name: Extract branch name
shell: bash
run: echo "branch=$(echo $(echo ${GITHUB_REF#refs/*/} | tr / _))" >> $GITHUB_OUTPUT
id: extract_branch

- name: Determine image to build
id: parse_image
shell: python
run: |
import os
build_target = "jupyter-pystata-licensed"
print(f"Will trigger build for: {build_target}")
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f'build_target={build_target}', file=fh)
echo "IMAGE_TAG=$(echo ${GITHUB_REF#refs/*/} | tr / _)"
echo "IMAGE_TAG=$(echo ${GITHUB_REF#refs/*/} | tr / _)" >> $GITHUB_ENV
- if: ${{ steps.parse_image.outputs.build_target }}
name: Sanitize image name
id: sanitize_name
run: |
IMAGE_NAME=$( sed 's/[^[:alnum:]]/_/g' <<< ${{ steps.parse_image.outputs.build_target }} );
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Login to Quay.io
id: login
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
image: jupyter-pystata-gen3-licensed
tags: ${{ steps.extract_branch.outputs.branch }}
dockerfiles: ./jupyter-pystata-gen3-licensed/Dockerfile
images: |
quay.io/cdis/jupyter-pystata-gen3-licensed:${{ env.IMAGE_TAG }}
- name: Push To quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
- name: Build and Push Image
uses: docker/build-push-action@v6
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/cdis
username: ${{ secrets.QUAY_SERVICE_ACCOUNT_USER }}
password: ${{ secrets.QUAY_SERVICE_ACCOUNT_PASSWORD }}
context: ./jupyter-pystata-gen3-licensed
file: "./jupyter-pystata-gen3-licensed/Dockerfile"
push: true
tags: |
quay.io/cdis/jupyter-pystata-gen3-licensed:${{ env.IMAGE_TAG }}
labels: ${{ steps.meta.outputs.labels }}
60 changes: 30 additions & 30 deletions .github/workflows/build_push_stata_user_licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
- uses: actions/checkout@v4
- uses: prewk/s3-cp-action@v2
with:
root-reserve-mb: 30000
swap-size-mb: 1024
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
- uses: actions/checkout@v2
- uses: prewk/[email protected]
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE: 's3://ctds-stata/Stata17Linux64.tar.gz'
DEST: './jupyter-pystata-user-licensed/resources/'
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
source: 's3://ctds-stata/StataNow18Linux64.tar.gz'
dest: './jupyter-pystata-user-licensed/resources/'

- name: Extract branch name
shell: bash
run: echo "::set-output name=branch::$(echo $(echo ${GITHUB_REF#refs/*/} | tr / _))"
id: extract_branch
run: |
echo "IMAGE_TAG=$(echo ${GITHUB_REF#refs/*/} | tr / _)"
echo "IMAGE_TAG=$(echo ${GITHUB_REF#refs/*/} | tr / _)" >> $GITHUB_ENV
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
- name: Login to Quay.io
id: login
uses: docker/login-action@v3
with:
image: jupyter-pystata-user-licensed
tags: ${{ steps.extract_branch.outputs.branch }}
dockerfiles: ./jupyter-pystata-user-licensed/Dockerfile
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

- name: Push To quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/cdis
username: ${{ secrets.QUAY_SERVICE_ACCOUNT_USER }}
password: ${{ secrets.QUAY_SERVICE_ACCOUNT_PASSWORD }}
images: |
quay.io/cdis/jupyter-pystata-user-licensed:${{ env.IMAGE_TAG }}
- name: Build and Push Image
uses: docker/build-push-action@v6
with:
context: ./jupyter-pystata-user-licensed
file: "./jupyter-pystata-user-licensed/Dockerfile"
push: true
tags: |
quay.io/cdis/jupyter-pystata-user-licensed:${{ env.IMAGE_TAG }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode/*
.DS_store
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: [email protected]:Yelp/detect-secrets
rev: v1.4.0
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
exclude: .lock
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.4.0",
"version": "1.5.0",
"plugins_used": [
{
"name": "ArtifactoryDetector"
Expand Down
2 changes: 2 additions & 0 deletions jupyter-pystata-gen3-licensed/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Stata17Linux64.tar.gz
StataNow18Linux64.tar.gz
stata.lic
16 changes: 9 additions & 7 deletions jupyter-pystata-gen3-licensed/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
FROM quay.io/cdis/jupyter-pystata-user-licensed:1.2.1
FROM quay.io/cdis/jupyter-pystata-user-licensed:feat_stata-base-update

USER root
RUN apt-get update
RUN apt-get install -y firefox
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.35.0/geckodriver-v0.35.0-linux64.tar.gz
RUN tar -xvzf geckodriver*
RUN mv geckodriver /bin/

COPY jupyter-pystata-gen3-licensed/resources/wait_for_license.sh /tmp/
COPY jupyter-pystata-gen3-licensed/resources/setup_licensed_notebook.py /tmp/
COPY ./resources/wait_for_license.sh /tmp/
COPY ./resources/setup_licensed_notebook.py /tmp/
RUN chmod 777 /tmp/wait_for_license.sh /tmp/setup_licensed_notebook.py

COPY ./resources/licensed_stata_session.ipynb $HOME
RUN chown $NB_USER $HOME/licensed_stata_session.ipynb

USER $NB_USER
RUN pip3 install selenium

# Pin stata_setup to avoid error on splash parameter
RUN pip3 uninstall --yes stata-setup
RUN pip3 install stata-setup==0.1.2
RUN pip3 install stata-setup


# Remove the notebook created in jupyter-pystata-user-licensed
RUN rm $HOME/Stata.ipynb
COPY jupyter-pystata-gen3-licensed/resources/licensed_stata_session.ipynb $HOME
8 changes: 4 additions & 4 deletions jupyter-pystata-gen3-licensed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ kubectl get secret stata-workspace-gen3-license-g3auto

To build, enter the root directory of this repo and run:
```
docker build -t stata-licensed -f jupyter-pystata-gen3-licensed/Dockerfile .
docker build -t stata-licensed -f jupyter-pystata-gen3-licensed/Dockerfile ./jupyter-pystata-gen3-licensed
docker run --name stata-licensed -p 8888:8888 stata-licensed /tmp/wait_for_license.sh --NotebookApp.base_url=/lw-workspace/proxy/ --NotebookApp.password='' --NotebookApp.token=''
docker run --name stata-licensed -p 8888:8888 stata-licensed /tmp/wait_for_license.sh --JupyterNotebookApp.base_url=/lw-workspace/proxy/ --JupyterNotebookApp.password='' --JupyterNotebookApp.token=''
```

(You will need a local copy of `Stata17Linux64.tar.gz`.)
(You will need a local copy of `StataNow18Linux64.tar.gz`.)

Then, with your license `stata.lic`,

```
docker cp stata.lic stata-licensed:/usr/local/stata17/stata.lic
docker cp stata.lic stata-licensed:/usr/local/stata18/stata.lic
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Licensed STATA Notebook Workspace\n",
"This notebook runs a licensed STATA MP session, managed by the Gen3 platform.\n",
Expand All @@ -11,38 +12,37 @@
"Because licenses are protected and limited, this workspace is limited to a single running STATA session, which has already been initialized via the cell below.\n",
"\n",
"Users who have an existing STATA license are encouraged to bring it to a self-supplied STATA workspace."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import stata_setup\n",
"stata_setup.config(\"/usr/local/stata17\", \"mp\")"
],
"outputs": [],
"metadata": {}
"stata_setup.config(\"/usr/local/stata18\", \"mp\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%stata\n",
". describe"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%mata\n",
"sqrt(4)"
],
"outputs": [],
"metadata": {}
]
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
browser = webdriver.Firefox(options=opts)

print("Checking for .lic file")
with open("/usr/local/stata17/stata.lic", "r") as lic_file:
with open("/usr/local/stata18/stata.lic", "r", encoding="utf-8") as lic_file:
print("Found stata.lic file")

print("Ready to open notebook")
browser.get("http://127.0.0.1:8888/lw-workspace/proxy/notebooks/licensed_stata_session.ipynb")
print("Notebook is opened")

actions = ActionChains(browser)
actions.pause(5)
actions.pause(10)
actions.perform()

# Down-arrow to get to the second cell in the notebook
actions.send_keys(Keys.DOWN)
Expand All @@ -31,14 +32,15 @@
actions.key_down(Keys.SHIFT)
actions.send_keys(Keys.ENTER)
actions.key_up(Keys.SHIFT)
actions.perform()
actions.pause(5)
actions.perform()

# Save notebook with output
print("Ready to save notebook")
actions.key_down(Keys.CONTROL)
actions.send_keys("S")
actions.key_up(Keys.CONTROL)
actions.pause(1)
actions.pause(5)
actions.perform()
actions.send_keys(Keys.ENTER)
actions.perform()
6 changes: 3 additions & 3 deletions jupyter-pystata-gen3-licensed/resources/wait_for_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

echo "Checking for license copied by sidecar"

while [ ! -f /usr/local/stata17/stata.lic ];
while [ ! -f /usr/local/stata18/stata.lic ];
do
sleep 5
echo "Checking for license"
if [ -f /data/stata.lic ]; then
echo "Found license"
mv /data/stata.lic /usr/local/stata17/stata.lic
mv /data/stata.lic /usr/local/stata18/stata.lic
echo "Copied license"
fi
done
Expand All @@ -25,6 +25,6 @@ python3 /tmp/setup_licensed_notebook.py
rm geckodriver*

echo "Init script done."
rm /usr/local/stata17/stata.lic
rm /usr/local/stata18/stata.lic

while true; do sleep 1; done
2 changes: 2 additions & 0 deletions jupyter-pystata-user-licensed/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Stata17Linux64.tar.gz
StataNow18Linux64.tar.gz
stata.lic
Loading

0 comments on commit 016ffbb

Please sign in to comment.