Skip to content

Commit

Permalink
Merge pull request #16 from dagster-io/funwithcontainercontext
Browse files Browse the repository at this point in the history
Add container_context to github action
  • Loading branch information
gibsondan authored Apr 19, 2022
2 parents a0dd192 + ba3103e commit 67a9213
Show file tree
Hide file tree
Showing 17 changed files with 24,697 additions and 24,094 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/example-container-context.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Example with container context
on: push

jobs:
container-context-example:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v1

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2

- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Cache Docker builds
uses: satackey/[email protected]
continue-on-error: true

- name: Run Dagster Cloud CI/CD action
# Here, use `uses: dagster-io/dagster-cloud-cicd-action/deploy@{version}`
# e.g. `uses: dagster-io/dagster-cloud-cicd-action/[email protected]`
uses: ./deploy
with:
location-file: ./example/container-context/locations.yaml
dagit-url: https://elementl.dogfood.dagster.cloud/dev
api-token: ${{ secrets.DAGSTER_AGENT_TOKEN }}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ Each location specified in the `locations.yaml` can have the following propertie

## Developing the CI/CD Action

The first time developing against the action, run:

```sh
npm install
```

The CI/CD action is run from the packaged files in the `dist/*` folder. When making a change, be sure to repackage the files:

```sh
Expand Down
14,432 changes: 7,295 additions & 7,137 deletions dist/deploy/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/deploy/index.js.map

Large diffs are not rendered by default.

14,428 changes: 7,293 additions & 7,135 deletions dist/preview/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/preview/index.js.map

Large diffs are not rendered by default.

14,432 changes: 7,295 additions & 7,137 deletions dist/update-only/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/update-only/index.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions example/container-context/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8-slim

RUN pip install \
dagster \
dagster-cloud

WORKDIR /opt/dagster/app

COPY repo.py /opt/dagster/app
8 changes: 8 additions & 0 deletions example/container-context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Minimal Example

This is a minimal example of a repo set up to use the CI/CD Action. The [`locations.yaml`](./locations.yaml) file
specifies to build the `github_action_demo_minimal` code location using the Dockerfile in the current
directory, using `repo.py` as an entry point.

The GitHub actions workflow for this example can be found at
[`.github/workflows/example-minimal.yml`](../../.github/workflows/example-minimal.yml).
9 changes: 9 additions & 0 deletions example/container-context/locations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
locations:
github_action_demo_container_context:
build: .
registry: 764506304434.dkr.ecr.us-west-2.amazonaws.com/github-action-demo-container-context
python_file: repo.py
container_context:
docker:
env_vars:
- BAR_ENV_VAR=bar
35 changes: 35 additions & 0 deletions example/container-context/repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from dagster import Field, RunRequest, StringSource, job, op, repository


@op(
config_schema={
"must_be_bar": Field(
StringSource,
)
},
)
def foo_op(context):
must_be_bar = context.op_config["must_be_bar"]
if must_be_bar != "bar":
raise Exception(f"Job fails if must_be_bar is not bar, instead was {must_be_bar}")


@op()
def foo_op_2(_):
pass


@job
def foo_job():
foo_op()
foo_op_2()


@job
def other_foo_job():
foo_op()


@repository
def foo_repo():
return [foo_job, other_foo_job]
4 changes: 2 additions & 2 deletions example/requirements-txt/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dagster==0.12.14
dagster-cloud==0.12.14
dagster
dagster-cloud
17 changes: 8 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 23 additions & 12 deletions src/dagsterCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ const LIST_LOCATION_QUERY = gql`
`;

const ADD_LOCATION_MUTATION = gql`
mutation ($location: LocationSelector!) {
addLocation(location: $location) {
mutation ($document: GenericScalar!) {
addLocationFromDocument(document: $document) {
__typename
... on WorkspaceEntry {
locationName
}
... on InvalidLocationError {
errors
}
... on PythonError {
message
stack
Expand All @@ -27,12 +30,15 @@ const ADD_LOCATION_MUTATION = gql`
`;

const UPDATE_LOCATION_MUTATION = gql`
mutation ($location: LocationSelector!) {
updateLocation(location: $location) {
mutation ($document: GenericScalar!) {
updateLocationFromDocument(document: $document) {
__typename
... on WorkspaceEntry {
locationName
}
... on InvalidLocationError {
errors
}
... on PythonError {
message
stack
Expand Down Expand Up @@ -68,27 +74,32 @@ export class DagsterCloudClient {
});
}

async updateLocation(location) {
async updateLocation(document) {
const locationList = await this.gqlClient.request(LIST_LOCATION_QUERY);
const locationNames = locationList.workspace.workspaceEntries.map(
(entry) => entry.locationName
);

let result;
if (!locationNames.includes(location.name)) {
result = (
if (!locationNames.includes(document.location_name)) {
const gql_result = (
await this.gqlClient.request(ADD_LOCATION_MUTATION, {
location: location,
document: document,
})
).addLocation;
);
result = gql_result.addLocationFromDocument;
} else {
result = (
const gql_result = (
await this.gqlClient.request(UPDATE_LOCATION_MUTATION, {
location: location,
document: document,
})
).updateLocation;
);
result = gql_result.updateLocationFromDocument;
}

if (result.__typename == "InvalidLocationError") {
throw new Error("Invalid location:\n" + result.errors.join("\n"))
}
if (result.__typename === "PythonError") {
throw new Error(result.message);
}
Expand Down
24 changes: 15 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export async function updateLocations(process, client, locations, imageTag) {
const workingDirectory = location["working_directory"];
const executablePath = location["executable_path"];
const attribute = location["attribute"];
const containerContext = location["container_context"]

if (
[pythonFile, packageName, moduleName].filter((x) => !!x).length != 1
Expand All @@ -145,20 +146,25 @@ export async function updateLocations(process, client, locations, imageTag) {
`${github.context.repo.repo}/tree/${shortSha}`;

const locationData = {
name: locationName,
location_name: locationName,
code_source: {
python_file: pythonFile,
package_name: packageName,
module_name: moduleName,
},
image: `${location["registry"]}:${imageTag}`,
pythonFile: pythonFile,
packageName: packageName,
moduleName: moduleName,
workingDirectory: workingDirectory,
executablePath: executablePath,
working_directory: workingDirectory,
executable_path: executablePath,
attribute: attribute,
commitHash: sha,
url: url,
git: {
commit_hash: sha,
url: url
},
container_context: containerContext,
};

const result = await client.updateLocation(locationData);
core.info(`Successfully updated location ${result}`);
core.info(`Updated location ${result}.`);
});
});
}
Expand Down
Loading

0 comments on commit 67a9213

Please sign in to comment.