Skip to content

Commit

Permalink
add action for docker hub
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-fontugne committed Jun 21, 2024
1 parent 73efbb0 commit 04d94d1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build + Push Docker images
run-name: Build + Push Docker images

on:
- push
- workflow_dispatch

jobs:
build-and-push:
name: Build and Push ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
- dockerfile: ./Dockerfile
name: psql-dump
context: ./
python-version: 3.11
steps:
- uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login into DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true
- name: Build + Push ${{ matrix.name }} image to DockerHub
uses: docker/build-push-action@v4
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: true
build-args:
PYTHON_VERSION=${{ matrix.python-version }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.name }}:${{ matrix.python-version }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.name }}:latest
3 changes: 3 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
context: .
volumes:
- ./dumps:/dumps
environment:
- PSQL_HOST=ihr-db.iijlab.net
- PSQL_ROLE=romain

# The commented out section below is an example of how to define a PostgreSQL
# database that your application can use. `depends_on` tells Docker Compose to
Expand Down
2 changes: 1 addition & 1 deletion configs/country_hegemony_v4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"database": "ihr",
"query": "select timebin, weight, weightscheme, tansitonly, asn_id as asn, country_id as country, hege from ihr_hegemony_country where af=4 and timebin>='{startdate.year}-{startdate.month}-{startdate.day}' and timebin<'{enddate.year}-{enddate.month}-{enddate.day}'",
"query": "select timebin, weight, weightscheme, transitonly, asn_id as asn, country_id as country, hege from ihr_hegemony_country where af=4 and timebin>='{startdate.year}-{startdate.month}-{startdate.day}' and timebin<'{enddate.year}-{enddate.month}-{enddate.day}'",
"dump_root": "/dumps/ihr/country_hegemony/ipv4/",
"dump_fname": "ihr_country_hegemony_ipv4"
}
5 changes: 4 additions & 1 deletion dumpit.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def dump(self, date, compress='lz4'):
# create directories if needed
os.makedirs(dump_folder, exist_ok=True)

cmd = r"""psql -d {db} -h {psql_host} -c "\copy ({query}) to '{fname}' csv header;" """.format(
cmd = r"""psql -d {db} -h {psql_host} -U {psql_role} -c "\copy ({query}) to '{fname}' csv header;" """.format(
db=self.config['database'],
psql_host=PSQL_HOST,
psql_role=PSQL_ROLE,
query=query,
fname=dump_folder+dump_fname
)
Expand Down Expand Up @@ -66,6 +67,8 @@ def dump(self, date, compress='lz4'):

global PSQL_HOST
PSQL_HOST = os.environ["PSQL_HOST"]
global PSQL_ROLE
PSQL_ROLE = os.environ["PSQL_ROLE"]

parser = argparse.ArgumentParser(
description='Dump data from the database to a CSV file')
Expand Down

0 comments on commit 04d94d1

Please sign in to comment.