Merge pull request #74 from simonsobs/dev #57
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: Build and test Docker image | |
# This workflow builds a Docker image and runs a container to test the image. | |
# Five seconds after it starts the container, it prints the logs of the container. | |
# Then, it checks if the container is running. If the container is not running, the | |
# workflow exits with an error. | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Build Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: false | |
tags: ${{ env.IMAGE_NAME }}:latest | |
- name: List Docker images | |
run: docker images | |
- name: Run Docker container | |
run: | | |
docker run --name test-container -d ${{ env.IMAGE_NAME }}:latest | |
sleep 5 | |
docker logs test-container | |
if [ "$(docker ps -f name=test-container -q)" = "" ]; then | |
echo "Container is not running." | |
exit 1 | |
fi | |
docker stop test-container |