Skip to content

Commit 3dfaff7

Browse files
authored
Merge pull request #9 from JunAishima/prefect3-pixi-upgrade
add pixi and Dockerfile-related files
2 parents b2a8193 + 82d81e5 commit 3dfaff7

10 files changed

Lines changed: 8090 additions & 30 deletions

File tree

.github/workflows/publish-ghcr.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
name: Create and publish a Docker image
3+
4+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
5+
on:
6+
push:
7+
branches: ['main']
8+
9+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
15+
jobs:
16+
build-and-push-image:
17+
runs-on: ubuntu-latest
18+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
19+
permissions:
20+
contents: read
21+
packages: write
22+
attestations: write
23+
id-token: write
24+
#
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v5
28+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
42+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
43+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
44+
- name: Build and push Docker image
45+
id: push
46+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
47+
with:
48+
context: .
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
53+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
54+
- name: Generate artifact attestation
55+
uses: actions/attest-build-provenance@v3
56+
with:
57+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
58+
subject-digest: ${{ steps.push.outputs.digest }}
59+
push-to-registry: true

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM ghcr.io/prefix-dev/pixi:latest
2+
3+
ENV TZ="America/New_York"
4+
5+
RUN apt-get -y update && \
6+
apt-get -y install git
7+
8+
COPY pixi.toml .
9+
COPY pixi.lock .
10+
# use `--locked` to ensure the lockfile is up to date with pixi.toml
11+
RUN pixi install --locked
12+
# create the shell-hook bash script to activate the environment
13+
RUN pixi shell-hook -s bash > /shell-hook
14+
15+
ENV PYTHONUNBUFFERED=1
16+
17+
COPY test.py .
18+
19+
RUN mkdir /etc/tiled
20+
RUN mkdir /.prefect -m 0777
21+
RUN mkdir /repo -m 0777
22+
23+
RUN /bin/bash /shell-hook
24+
25+
#now reapply deployment to push the image that is being created
26+
ENTRYPOINT ["pixi", "run"]
27+
CMD ["python", "-m", "test", "arg"]

analysis.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212
import numpy as np
1313
from prefect import flow, get_run_logger, task
14+
from prefect.blocks.system import Secret
1415
from tiled.client import from_profile
1516

1617
from ophyd.utils.epics_pvs import data_shape, data_type
1718
from event_model import compose_run
1819
from typing import Iterable, TypedDict
1920

2021

21-
tiled_client = from_profile("nsls2")["cms"]
22+
api_key = Secret.load("tiled-cms-api-key", _sync=True).get()
23+
tiled_client = from_profile("nsls2", api_key=api_key)["cms"]
2224
tiled_client_raw = tiled_client["raw"]
2325
# tiled_client_processed = tiled_client["sandbox"]
2426
cms_sandbox_tiled_client = tiled_client["bluesky_sandbox"]

data_validation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import time as ttime
22

33
from prefect import flow, get_run_logger, task
4+
from prefect.blocks.system import Secret
45
from tiled.client import from_profile
56

67

78
@task(retries=2, retry_delay_seconds=10)
89
def read_all_streams(beamline_acronym, uid):
910
logger = get_run_logger()
10-
tiled_client = from_profile("nsls2")
11+
api_key = Secret.load("tiled-cms-api-key", _sync=True).get()
12+
tiled_client = from_profile("nsls2", api_key=api_key)
1113
run = tiled_client[beamline_acronym]["raw"][uid]
1214
logger.info(f"Validating uid {run.start['uid']}")
1315
start_time = ttime.monotonic()

linker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from prefect import task, get_run_logger
2+
from prefect.blocks.system import Secret
23
from pathlib import Path
34
from tiled.client import from_profile
45
import os
56
import glob
67

78
#tiled_client = from_uri('https://tiled.nsls2.bnl.gov')
8-
tiled_client = from_profile("nsls2")['cms']
9+
api_key = Secret.load("tiled-cms-api-key", _sync=True).get()
10+
tiled_client = from_profile("nsls2", api_key=api_key)['cms']
911
tiled_client_raw = tiled_client["raw"]
1012

1113
#logger = logging.getLogger()

0 commit comments

Comments
 (0)