Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

Services and Volumes

I have successfully setup two static analysis jobs within my workflow, and I feel like I got all the way up to the final command ... But cannot figure out the last bit!

In this particular job I have 4 services all successfully setup, but they cannot seem to connect to the volumes I specified. I am trying to map my repository to the /var/www/ folder inside the container. Here is my workflow, the first two jobs run perfectly but when I try to access the repo files within the container it is empty:

name: CI

on:
pull_request:
branches:
- staging

jobs:
phpunit:
runs-on: ubuntu-latest
services:
app:
image: php:7.2-fpm
ports:
- 9000
volumes:
- $GITHUB_WORKSPACE:/var/www/html
options: --name opus_app
steps:
- name: Checkout Code
uses: actions/checkout@v1
run: |
- name: Print directory
run: docker exec opus_app pwd

 

**EDIT**
In case anyone finds this issue, the real issue is that you cannot map volumes to your codebase BEFORE checking out your codebase ... so the volumes inside of services is a bit limited to only sharing data between services, where it gets the data from not too sure, but I got around this by using docker-compose to build my services AFTER checking out the code!

2 Replies
Highlighted
waj
Copilot Lvl 2
Message 2 of 3

Re: Services and Volumes

I found a workaround for this. I'm using an nginx server to host the build directory generated during the build process. But there are two issues here. First, the volumes options for the services apparently are not working. So I pass a -v parameter with options insted. The second issue is that the service is started before the code is checked out, and that action seems to be re-creating the working directory, but because the service is already running mapped to the old directory it wont see the new content generated there.

 

My solution then is to start the service with a well known name and then restart it before using it. This is the service declaration:

 

services:
  nginx:
    image: nginx
    options: -v ${{ github.workspace }}/build:/usr/share/nginx/html --name nginx
 
And once the content is generated and ready to be served, the container is restarted:
 
- name: Restart nginx
  uses: docker://docker
  with:
    args: docker restart nginx
 
After that nginx will be serving the generated content just fine!
 
Highlighted
Copilot Lvl 2
Message 3 of 3

Re: Services and Volumes

Thanks for replying! I did end up just replacing it with a complete docker compose file.

I already had a working local dev environment using compose, and didn't realize that I could just call the same 'docker-compose up' inside of actions! Then you can make use of shared volumes using compose options and more advanced networking options.

So I now have a full environment inside my workflow with an empty DB, that starts up 5 containers in about 2 min.

Currently only using it for CI testing but it works fantastic and is super fast.