Docker Image CI #119
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] | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
POSTGRES_IMAGE: "postgres:16-alpine" | |
CLAIR_VERSION: "v2.1.8" | |
CLAIR_LOCAL_SCAN_IMAGE: "arminc/clair-local-scan" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver: docker | |
install: true | |
- name: Build image | |
run: docker build -t $CLAIR_LOCAL_SCAN_IMAGE --build-arg VERSION=$CLAIR_VERSION clair/v2 | |
- name: Start Postgres and run clair | |
run: | | |
docker pull $POSTGRES_IMAGE | |
docker run -d --name postgres -e 'PGDATA=/var/lib/postgresql/clair' -e POSTGRES_PASSWORD=password -e 'POSTGRES_INITDB_ARGS=--auth-local=md5' $POSTGRES_IMAGE | |
- name: Wait for database | |
run: | | |
sleep 30 | |
- name: Docker Postgres info | |
run: | | |
docker ps -a | |
docker logs postgres | |
- name: Run Clair | |
run: | | |
docker run --rm -d --link postgres:postgres -e PGPASSWORD=password $POSTGRES_IMAGE pg_isready -U postgres -h postgres | |
docker run -d --name clair --link postgres:postgres $CLAIR_LOCAL_SCAN_IMAGE | |
- name: Wait for clair | |
run: | | |
sleep 10 | |
- name: Docker Postgres info | |
run: | | |
docker ps -a | |
docker logs postgres | |
- name: Docker Clair info | |
run: | | |
docker ps -a | |
docker logs clair | |
- name: Checking | |
run: | | |
./check.sh | |
- name: Docker logs | |
run: | | |
docker logs clair | |
- name: Tag images | |
run: | | |
docker stop clair | |
docker stop postgres | |
docker commit postgres arminc/clair-db:$(date +%Y-%m-%d) | |
docker tag arminc/clair-db:$(date +%Y-%m-%d) arminc/clair-db:latest | |
docker tag $CLAIR_LOCAL_SCAN_IMAGE ${CLAIR_LOCAL_SCAN_IMAGE}:${CLAIR_VERSION}_${GITHUB_SHA} | |
docker images | |
- name: Login to DockerHub | |
if: github.repository_owner == 'arminc' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Push images | |
if: github.repository_owner == 'arminc' | |
run: | | |
docker push ${CLAIR_LOCAL_SCAN_IMAGE}:${CLAIR_VERSION}_${GITHUB_SHA} | |
docker push $CLAIR_LOCAL_SCAN_IMAGE:latest | |
docker push arminc/clair-db:$(date +%Y-%m-%d) | |
docker push arminc/clair-db:latest |