protocol-builder-mock/.github/workflows/create-docker-action.yml

102 lines
2.6 KiB
YAML
Raw Permalink Normal View History

2022-01-04 12:58:08 -05:00
name: Create and publish a Docker image
on:
push:
2024-12-11 07:38:07 -05:00
branches: ['main', 'chore/*', 'feature/*', 'bug/*', 'dev']
2022-01-04 12:58:08 -05:00
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
2022-06-20 13:25:18 -04:00
SQLALCHEMY_DATABASE_URI: "postgresql://postgres:postgres@localhost:5432/pb_test"
PGPASSWORD: postgres
2022-01-04 12:58:08 -05:00
jobs:
run_tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout repository
2025-01-27 13:13:54 -05:00
uses: actions/checkout@v4
- uses: browser-actions/setup-chrome@latest
with:
chrome-version: stable
2022-06-20 16:21:00 -04:00
- run: python -V
2022-06-20 16:15:33 -04:00
- uses: actions/setup-python@v4
with:
python-version: '3.9'
2022-06-20 15:12:30 -04:00
2022-06-20 15:15:28 -04:00
- name: Setup Database
2022-06-20 15:17:36 -04:00
run: psql -h localhost -c 'create database pb_test;' -U postgres
2022-06-20 15:12:30 -04:00
- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
2022-06-20 16:18:29 -04:00
python -V
2022-06-20 15:12:30 -04:00
- name: Upgrade pip in virtual environments
shell: python
run: |
import os
import pip
with open(os.environ["GITHUB_ENV"], mode="a") as io:
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
- name: Install Poetry
run: |
2022-06-20 16:22:39 -04:00
pip install --constraint=.github/workflows/constraints.txt poetry
2022-06-20 15:12:30 -04:00
poetry --version
2022-06-20 16:00:59 -04:00
poetry install
2022-06-20 16:05:59 -04:00
poetry env use 3.9
2022-06-20 16:18:29 -04:00
python -V
2022-06-20 16:00:59 -04:00
2022-06-20 15:12:30 -04:00
- name: Run the tests
2022-06-20 16:18:29 -04:00
run: |
ls -a
poetry run pytest
2022-01-04 12:58:08 -05:00
build-and-push-image:
needs:
- run_tests
2022-01-04 12:58:08 -05:00
runs-on: ubuntu-latest
2024-12-11 07:46:51 -05:00
if: github.ref == 'refs/heads/main' || 'refs/heads/dev'
2022-01-04 12:58:08 -05:00
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
2025-01-27 13:13:54 -05:00
uses: actions/checkout@v4
2022-01-04 12:58:08 -05:00
- name: Log in to the Container registry
2025-01-27 13:13:54 -05:00
uses: docker/login-action@v3
2022-01-04 12:58:08 -05:00
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
2025-01-27 13:13:54 -05:00
uses: docker/metadata-action@v5
2022-01-04 12:58:08 -05:00
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
2025-01-27 13:13:54 -05:00
uses: docker/build-push-action@v6
2022-01-04 12:58:08 -05:00
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}