-
Notifications
You must be signed in to change notification settings - Fork 1
48 lines (41 loc) · 1.2 KB
/
docker-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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@v5
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