Skip to content

Commit 0247e66

Browse files
authored
Merge pull request #2 from open-data-rescue/create-docker-image
Build docker image logic and some typo fixes
2 parents 64e9cc0 + 71910c5 commit 0247e66

File tree

6 files changed

+145
-5
lines changed

6 files changed

+145
-5
lines changed

.github/workflows/deploy.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
name: "Build a Docker image for deployment"
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- 'v*'
10+
workflow_dispatch:
11+
inputs:
12+
logLevel:
13+
description: 'Log level'
14+
required: true
15+
default: 'warning'
16+
type: choice
17+
options:
18+
- info
19+
- warning
20+
- debug
21+
22+
jobs:
23+
release:
24+
runs-on: ubuntu-latest
25+
26+
# No env...
27+
steps:
28+
- name: Maximize build space
29+
uses: easimon/maximize-build-space@master
30+
with:
31+
swap-size-mb: 4096
32+
temp-reserve-mb: 4096
33+
root-reserve-mb: 16384
34+
remove-dotnet: 'true'
35+
remove-android: 'true'
36+
remove-haskell: 'true'
37+
38+
- uses: actions/checkout@v3
39+
40+
- name: Log in to the Container registry
41+
uses: docker/login-action@v2
42+
with:
43+
registry: ${{ env.REGISTRY }}
44+
username: ${{ github.repository_owner }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Extract metadata (tags, labels) for Docker
48+
id: meta
49+
uses: docker/metadata-action@v4
50+
with:
51+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
52+
tags: |
53+
type=ref,event=branch
54+
type=ref,event=pr
55+
type=semver,pattern={{version}}
56+
type=semver,pattern={{major}}.{{minor}}
57+
type=semver,pattern=latest
58+
59+
- name: Set up Docker Buildx
60+
id: buildx
61+
uses: docker/setup-buildx-action@v2
62+
63+
- name: Builder instance name
64+
run: echo ${{ steps.buildx.outputs.name }}
65+
66+
- name: Available platforms
67+
run: echo ${{ steps.buildx.outputs.platforms }}
68+
69+
- name: Cache Docker layers
70+
uses: actions/cache@v3
71+
with:
72+
path: /tmp/.buildx-cache
73+
key: ${{ runner.os }}-buildx-${{ github.sha }}
74+
restore-keys: |
75+
${{ runner.os }}-buildx-
76+
77+
#
78+
- name: Build and Push the image
79+
id: docker_push
80+
uses: docker/build-push-action@v4
81+
with:
82+
context: ./
83+
file: ./Dockerfile
84+
builder: ${{ steps.buildx.outputs.name }}
85+
push: true
86+
tags: ${{ steps.meta.outputs.tags }}
87+
labels: ${{ steps.meta.outputs.labels }}
88+
cache-from: type=local,src=/tmp/.buildx-cache
89+
cache-to: type=local,dest=/tmp/.buildx-cache-new
90+
91+
# Needed to prevent cache from growing forever (see https://github.com/docker/build-push-action/issues/252)
92+
- name: Move cache
93+
run: |
94+
rm -rf /tmp/.buildx-cache
95+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile ~/.gitignore_global
6+
7+
/log
8+
/tmp
9+
tmp/*
10+
rerun.txt
11+
*.DS_Store
12+
.project
13+
.docker-sync
14+
.envrc
15+
.vscode
16+
17+
# Ignore pow environment settings
18+
.powenv

DRAW-post-processing/database_connection.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@
1010
phase_2_errors=[]
1111
duplicateless=[]
1212

13+
#
1314
db_user=os.environ.get('DRAW_local_db_user')
1415
db_passwd=os.environ.get('DRAW_local_db_pass')
1516
db_name=os.environ.get('DRAW_local_db_name')
16-
db_host=os.environ.get('DRAW_db_host')
17+
db_host=os.environ.get('DRAW_db_host',"127.0.0.1")
18+
db_port=os.environ.get('DRAW_db_port',"3306")
1719

1820
# connection to copy of database on local machine
1921
conn = mysql.connector.connect(
2022
##### FOLLOWING 3 VARIABLES TO BE CONFIGURED AS NECESSARY FOR LOCAL MACHINE: #####
2123
user=db_user,
2224
password=db_passwd,
2325
database=db_name,
24-
host=db_host
26+
host=db_host,
27+
port=db_port
2528
)
2629

2730
cursor = conn.cursor()
2831

29-
url = "mysql+mysqlconnector://"+db_user+":"+db_passwd+"@l"+db_host+"/"+db_name
32+
# Problem? dialect+driver://username:password@host:port/database
33+
url = "mysql+mysqlconnector://"+db_user+":"+db_passwd+"@"+db_host+":"+db_port+"/"+db_name
3034
engine = sqlalchemy.create_engine(url)
3135

3236

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##### Required packages for the draw python code
2+
mysql-connector-python
3+
sqlalchemy
4+
matplotlib
5+
Numpy
6+
pandas

DRAW-post-processing/sef_gen.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def getPeriod(sef_type):
3333

3434

3535
def getFilename(sef_type,type_result_set):
36-
filename=os.environ.get('DRAW_sef_folder')+os.sep+"McGill_DRAW_1491_"
36+
# FileNotFoundError: [Errno 2] No such file or directory: 'SEF/McGill_DRAW_1491_1874-10_1934-5-atb.tsv'
37+
filename=os.environ.get('DRAW_sef_folder', 'SEF')+os.sep+"McGill_DRAW_1491_"
3738

3839
if len(type_result_set)>0:
3940
sorted_type_results=sorted(type_result_set)
@@ -106,7 +107,7 @@ def generateSEF(sef_type):
106107
f.write ("Lat\t45.5\n")
107108
f.write ("Lon\t-73.59\n")
108109
f.write ("Alt\t49\n")
109-
f.write ("Source\McGill\n")
110+
f.write ("Source\tMcGill\n")
110111
f.write ("Link\thttps://draw.geog.mcgill.ca/\n")
111112
f.write ("Vbl\t" + config.sef_type_to_unit[sef_type]+"\n")
112113
f.write ("Stat\t")

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Dockerfile
2+
# To run the Python post processing
3+
#
4+
FROM python:3
5+
6+
# WORKDIR /setup
7+
ADD ./DRAW-post-processing /opt/draw-post-processing
8+
WORKDIR /opt/draw-post-processing
9+
10+
RUN mkdir /opt/draw-post-processing/SEF
11+
12+
# Install the packages that are needed
13+
RUN pip install --no-cache-dir -r requirements.txt
14+
15+
# Run the post process script
16+
CMD [ "python", "./execute_post_process.py" ]

0 commit comments

Comments
 (0)