Merge pull request #152 from pycontw/fix-docker-volume #495
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image CI | |
on: | |
push: | |
branches: [ master, prod ] | |
pull_request: | |
branches: [ master, prod ] | |
env: | |
RC_NAME: asia-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/data-team/pycon-etl | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} | |
- name: Configure docker to use gcloud command-line tool as a credential helper | |
run: | | |
gcloud auth configure-docker asia-east1-docker.pkg.dev | |
- name: Pull cache | |
run: | | |
docker pull ${RC_NAME}:cache || true | |
- name: Build the Docker image | |
run: | | |
docker build -t ${RC_NAME}:cache --cache-from ${RC_NAME}:cache . | |
docker build -t ${RC_NAME}:test --cache-from ${RC_NAME}:cache -f Dockerfile.test . | |
- name: Run test | |
run: | | |
docker run -d --rm -p 8080:8080 --name airflow -v $(pwd)/dags:/opt/airflow/dags -v $(pwd)/fixtures:/opt/airflow/fixtures ${RC_NAME}:test webserver | |
sleep 10 | |
- name: Push cache to Google Container Registry | |
if: success() | |
run: | | |
docker push ${RC_NAME}:cache | |
- name: Push staging to Google Container Registry | |
if: github.ref == 'refs/heads/master' && success() | |
run: | | |
docker tag ${RC_NAME}:cache ${RC_NAME}:staging | |
docker push ${RC_NAME}:staging | |
- name: Push prod version to Google Container Registry | |
if: github.ref == 'refs/heads/prod' && success() | |
run: | | |
docker tag ${RC_NAME}:cache ${RC_NAME}:latest | |
docker push ${RC_NAME}:latest |