Skip to content

New Push/PR On main - Building and Testing Docker Image #6

New Push/PR On main - Building and Testing Docker Image

New Push/PR On main - Building and Testing Docker Image #6

name: Docker Build and Test
run-name: New Push/PR On ${{ github.ref_name }} - Building and Testing Docker Image
on:
- push
- pull_request
jobs:
lint-and-build:
runs-on: ubuntu-latest
steps:
- name: Check out the repo content
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Lint Dockerfile
uses: hadolint/hadolint-action@v1.5.0
with:
dockerfile: "Dockerfile"
- name: Build the Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: false
load: true
tags: johnnyknighten/test:latest
cache-from: type=gha
cache-to: type=gha,mode=max
container-tests:
runs-on: ubuntu-latest
needs:
- lint-and-build
steps:
- name: Test the Docker image TEST_VAR equals content of text_content.text
run: docker run --rm johnnyknighten/test:latest -c "cat test_content.txt | grep -q \"Hello World\""
- name: Check nano is installed
run: docker run --rm johnnyknighten/test:latest -c "nano --version"