Fix building Docker image #25
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 publish Docker image | |
on: | |
push: | |
branches: [ main ] | |
release: | |
types: [published] | |
concurrency: | |
group: ${{ github.workflow }} | |
cancel-in-progress: true | |
env: | |
REGISTRY: ghcr.io | |
REGISTRY_USER: ${{ github.repository_owner }} | |
REGISTRY_PASS: ${{ secrets.GITHUB_TOKEN }} | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-docker: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Bump commit version | |
if: github.event_name == 'push' | |
shell: bash | |
run: | | |
python -m pip install bump-my-version | |
bump-my-version bump commit --no-commit --verbose --serialize "{major}.{minor}.{patch}-{distance_to_latest_tag}" | |
- name: Login to ${{ env.REGISTRY }} registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ env.REGISTRY_USER }} | |
password: ${{ env.REGISTRY_PASS }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
#type=semver,pattern={{major}}.{{minor}} | |
#type=semver,pattern={{major}} | |
- name: Build and export to Docker | |
uses: docker/build-push-action@v6 | |
with: | |
load: true | |
tags: ${{ steps.meta.outputs.tags }} | |
- name: Test | |
run: | | |
docker run --rm ${{ steps.meta.outputs.tags }} -e TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} | |
# Wait for server to start | |
sleep 30 | |
# Check if status code is correct | |
expected_status="HTTP/1.1 200 OK" | |
actual_status=$(curl -I -X GET http://localhost:5000 | head -n 1) | |
if [[ ! "$actual_status" =~ "$expected_status" ]]; then | |
echo 'Failed while checking the status code after request to /' | |
echo 'expected: ' $expected_status | |
echo 'actual: ' $actual_status | |
exit 1; | |
fi | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |