J. Doe
J. Doe

Reputation: 13103

Github Actions Docker can't find file

I have this very simple project: https://github.com/Jasperav/cas_docker. I want to execute setup.cql (although empty) in my docker container. This is my yml file:

name: tests-cassandra

on: push

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      cassandra:
        image: cassandra
        ports:
          - 9042:9042
        options: --health-cmd "cqlsh --debug" --health-interval 5s --health-retries 10
    steps:
      - uses: actions/checkout@v2
      - run: |
          ls
          docker exec -i ${{ job.services.cassandra.id }} cqlsh -f setup.cql

Docker is able to see setup.cql is in the current dir before running the docker exec command because ls returns setup.cql:

enter image description here

How to run a .cql script in Docker in Github Actions

Upvotes: 1

Views: 3247

Answers (1)

Edward Romero
Edward Romero

Reputation: 3104

Your service doesn't have access to the local file. Make sure to create a volume and then you will be able to run your command. The below solution assumes file setup.cql exists at the root of your repo directory

Repo Structure Assumption

repo/
  .github/workflows/your-worflow.yaml
  setup.cql
  ... any other files/dirs

Workflow Update

services:
  cassandra:
    image: cassandra
    ports:
      - 9042:9042
    options: --health-cmd "cqlsh --debug" --health-interval 5s --health-retries 10
    volumes: 
       - ${{ github.workspace }}:/workspace
steps:
  - uses: actions/checkout@v2
  - run: docker exec -i ${{ job.services.cassandra.id }} cqlsh -f /workspace/setup.cql

Upvotes: 4

Related Questions