Build and Push Server Docker Image #30
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 Push Server Docker Image | |
on: | |
workflow_dispatch: | |
workflow_call: | |
permissions: | |
packages: write | |
contents: read | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12.7' | |
- name: Install build dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install hatchling | |
pip install -e . | |
- name: Get versions from __about__.py | |
id: get_version | |
run: | | |
python -c " | |
import os | |
def find_about_file(start_path='src'): | |
for root, dirs, files in os.walk(start_path): | |
if '__about__.py' in files: | |
return os.path.join(root, '__about__.py') | |
return None | |
about_file = find_about_file() | |
if about_file: | |
with open(about_file, 'r') as f: | |
exec(compile(f.read(), about_file, 'exec'), globals()) | |
print(f'version=v{__version__}') | |
else: | |
print('Error: __about__.py not found') | |
" >> $GITHUB_OUTPUT | |
- name: Build package | |
run: | | |
python -m hatchling build | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/h3xitsec/h3xrecon/server | |
tags: | | |
type=raw,value=${{ steps.get_version.outputs.version }} | |
type=raw,value=latest | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push server image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./ | |
file: ./Dockerfile.server | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
platforms: linux/amd64,linux/arm64 |