diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..9434d46 --- /dev/null +++ b/.github/workflows/docker.yml @@ -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 diff --git a/compose.yaml b/compose.yaml index e617364..6c0ba9b 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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 diff --git a/configs/country_hegemony_v4.json b/configs/country_hegemony_v4.json index 3738ddf..4d54612 100644 --- a/configs/country_hegemony_v4.json +++ b/configs/country_hegemony_v4.json @@ -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" } diff --git a/dumpit.py b/dumpit.py index 35e9ccd..cfc46e1 100644 --- a/dumpit.py +++ b/dumpit.py @@ -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 ) @@ -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')