Skip to content
# https://github.com/marketplace/actions/build-and-push-docker-images
name: Build, Test and Push Docker Image
jobs:
base-image:
on:
push:
paths:
- requirements.txt
- Dockerfile
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image and push
uses: docker/build-push-action@v5
with:
push: false
target: base
tags: mercury/farmers-report-base:latest
outputs: type=docker,dest=/tmp/base-image.tar
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: BaseImage
path: /tmp/base-image.tar
test-code:
on: push
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: BaseImage
path: /tmp
- name: Load image
run: |
docker load --input /tmp/base-image.tar
- name: Test code
run: |
docker run -v $(pwd):/code -w /code mercury/farmers-report-base:latest Rscript /code/tests/testthat.R
docker-image:
on:
pull_request:
branches:
- master
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image and push
uses: docker/build-push-action@v5
with:
tags: mercury/farmers-report:latest