Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a GitHub Actions workflow for publishing an image in GHCR. #2

Merged
merged 11 commits into from
Jan 29, 2025
Merged
51 changes: 51 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Docker

on:
push:
branches: [master]
# Publish semver tags as releases.
tags: ["v*.*.*"]

env:
REGISTRY: ghcr.io
REGISTRY_WITH_PATH: ghcr.io/${{ github.repository_owner }}

jobs:
build-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_WITH_PATH }}/odk-publish
# Generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}.{{hotfix}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ ENV PATH /code/node_modules/.bin:$PATH
COPY package.json package-lock.json tailwind.config.js postcss.config.js /code/
RUN npm install --silent
COPY config/assets config/assets
COPY config/static config/static
# Every template dir using Tailwind must be added below
COPY apps/eportal/templates apps/eportal/templates
COPY apps/inventory/templates apps/inventory/templates
COPY apps/inventory_materials/templates apps/inventory_materials/templates
COPY apps/portal_patterns/templates apps/portal_patterns/templates
COPY config/templates config/templates
COPY apps/patterns/templates apps/patterns/templates
RUN npm run build

FROM python:3.11-slim-bookworm as base
FROM python:3.12-slim-bookworm as base

# Install packages needed to run your application (not build deps):
# mime-support -- for mime types when serving static files
Expand Down
2 changes: 1 addition & 1 deletion apps/odk_publish/etl/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def generate_and_save_app_user_collect_qrcodes(project: Project):
image = create_app_user_qrcode(
app_user=central_app_users[app_user.name],
base_url=client.session.base_url,
central_id=project.central_id,
project_id=project.central_id,
project_name_prefix=project.name,
)
app_user.qr_code.save(
Expand Down
6 changes: 5 additions & 1 deletion apps/odk_publish/etl/odk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def __init__(self, base_url: str, project_id: int | None = None):
config_path = Path("/tmp/.pyodk_config.toml")
if not config_path.exists():
config_path.write_text(CONFIG_TOML)
# Create stub cache file if it doesn't exist, so that pyodk doesn't complain
cache_path = Path("/tmp/.pyodk_cache.toml")
if not cache_path.exists():
cache_path.write_text('token = ""')
# Create a session with the given authentication details and supply the
# session to the super class, so it doesn't try and create one itself
server_config = self.get_config(base_url=base_url)
Expand All @@ -49,7 +53,7 @@ def __init__(self, base_url: str, project_id: int | None = None):
api_version="v1",
username=server_config.username,
password=server_config.password.get_secret_value(),
cache_path=None,
cache_path=str(cache_path),
)
super().__init__(config_path=str(config_path), session=session, project_id=project_id)
# Update the stub config with the environment-provided authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def handle(self, *args, **options):
logger.info("Creating Projects...")
project = odk_publish.Project.objects.create(
name="Caktus Test",
project_id=1,
central_id=1,
central_server=central_server,
)
odk_publish.Project.objects.create(
name="Other Project",
project_id=5,
central_id=5,
central_server=myodkcloud,
)
logger.info("Creating TemplateVariable...")
Expand All @@ -61,6 +61,7 @@ def handle(self, *args, **options):
app_user = odk_publish.AppUser.objects.create(
name=center_id,
project=project,
central_id=1,
)
odk_publish.AppUserTemplateVariable.objects.create(
app_user=app_user, template_variable=center_id_var, value=center_id
Expand Down
3 changes: 2 additions & 1 deletion config/settings/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "localhost").split(":")

### ADMINS and MANAGERS
ADMINS = (("Caktus Team", "team@caktusgroup.com"),)
ADMIN_EMAIL = os.getenv("ADMIN_EMAIL")
ADMINS = (("Admin", ADMIN_EMAIL),)

# STATIC
# ------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions config/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<script>htmx.logAll()</script>
<link href="{% static 'css/main.css' %}" rel="stylesheet" />
{# favicon #}
<link rel="shortcut icon"
href="{% static 'favicon.ico' %}"
type="image/x-icon" />
{% comment "FIXME: Uncomment when the favicon file is added. Currently causing an error when DEBUG=False" %}
<link rel="shortcut icon" href="{% static 'favicon.ico' %}" type="image/x-icon" />
{% endcomment %}
<title>
{% block title %}
ODK Publish
Expand Down