Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/todoapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: todoapp

on:
push:
branches:
- main
paths:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, me too, but this seemed reasonable:

I kept the paths filter in the workflow so that we don't use up GitHub Actions minutes unnecessarily: https://github.com/dagger/dagger/pull/1693/files#diff-472b1b8ec4b92806685394e7aad78734b8ca06feaa04491d31adfd51e5ebba95R7-R9

Even if Netlify does the right thing, we are still a private repository and pay for GitHub Actions build minutes...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I just realized that this is about optimizing our own CI, not the highly visible example in the getting started guide. So I'm less sad now ;)
  • How much visibility does Github Actions give us into minute spending? I would curious to measure the real cost without path filtering, and then compare it with path filtering. That would be very useful information, and might inform feature prioritization. Huge cost -> prioritize making our caching smarter. Small cost -> it can wait.

- '.github/workflows/todoapp.yml'
- 'pkg/universe.dagger.io/examples/todoapp/**'

env:
# This needs to be unique across all of Netlify
APP_NAME: todoapp-dagger-europa
NETLIFY_TEAM: blocklayer
# https://app.netlify.com/user/applications/personal
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
DAGGER_LOG_FORMAT: plain

jobs:
dagger:
name: "Deploy todoapp to Netlify"
runs-on: ubuntu-latest
steps:
- name: "Clone repository"
uses: actions/checkout@v2
with:
fetch-depth: 0

# TODO: maybe use Dagger action post 0.2.0-beta.1
- name: "Setup Go"
uses: actions/setup-go@v1
with:
go-version: 1.16

- name: "Install dev Dagger"
run: |
make dagger

- name: "Dagger"
run: |
cd pkg/universe.dagger.io/examples/todoapp
${{ github.workspace }}/cmd/dagger/dagger do deploy
66 changes: 63 additions & 3 deletions docs/getting-started/1201-ci-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ displayed_sidebar: europa

# From local dev to CI environment

Dagger can be used with any CI environment (no migration required) and has two important advantages which make the overall experience less error-prone and more efficient:

1. Instead of YAML you write CUE: typed configuration with built-in formatting
2. Configuration is executed in buildkit, the execution engine at the heart of Docker

This makes any CI environment with Docker pre-installed work with Dagger out of the box.
We started with [CI environments that you told us you are using](https://github.com/dagger/dagger/discussions/1677).
We will configure a production deployment for the same application that we covered in the previous page.

:::note
If you cannot find your CI environment below, [let us know via this GitHub discussion](https://github.com/dagger/dagger/discussions/1677).
:::

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

<Tabs defaultValue="github-actions"
Expand All @@ -13,23 +26,70 @@ values={[
{label: 'GitHub Actions', value: 'github-actions'},
{label: 'CircleCI', value: 'circleci'},
{label: 'GitLab', value: 'gitlab'},
{label: 'Jenkins', value: 'jenkins'},
{label: 'Tekton', value: 'tekton'},
]}>

<TabItem value="github-actions">

Since Dagger early access required a GitHub account, GitHub Actions seems like a reasonable starting point.
`.github/workflows/todoapp.yml`

```yaml
name: todoapp

push:
# Trigger this workflow only on commits pushed to the main branch
branches:
- main

# Dagger plan gets configured via client environment variables
env:
# This needs to be unique across all of netlify.app
APP_NAME: todoapp-dagger-europa
NETLIFY_TEAM: dagger
# https://app.netlify.com/user/applications/personal
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
DAGGER_LOG_FORMAT: plain

jobs:
dagger:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Deploy to Netlify
# https://github.com/dagger/dagger-for-github
uses: dagger/[email protected]
with:
workdir: pkg/universe.dagger.io/examples/todoapp
plan: .
do: deploy
```

</TabItem>

<TabItem value="circleci">

If you would like us to document this CI environment next, mention it here: [dagger#1677](https://github.com/dagger/dagger/discussions/1677)
If you would like us to document CircleCI next, vote for it here: [dagger#1677](https://github.com/dagger/dagger/discussions/1677)

</TabItem>

<TabItem value="gitlab">

If you would like us to document this CI environment next, mention it here: [dagger#1677](https://github.com/dagger/dagger/discussions/1677)
If you would like us to document GitLab next, vote for it here: [dagger#1677](https://github.com/dagger/dagger/discussions/1677)

</TabItem>

<TabItem value="jenkins">

If you would like us to document Jenkins next, vote for it here: [dagger#1677](https://github.com/dagger/dagger/discussions/1677)

</TabItem>

<TabItem value="tekton">

If you would like us to document Tekton next, vote for it here: [dagger#1677](https://github.com/dagger/dagger/discussions/1677)

</TabItem>

Expand Down
1 change: 1 addition & 0 deletions pkg/universe.dagger.io/examples/todoapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 3 additions & 0 deletions pkg/universe.dagger.io/examples/todoapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Todo APP

[Dagger documentation website](https://docs.dagger.io/)
28 changes: 0 additions & 28 deletions pkg/universe.dagger.io/examples/todoapp/base.cue

This file was deleted.

40 changes: 0 additions & 40 deletions pkg/universe.dagger.io/examples/todoapp/dev/dev.cue

This file was deleted.

94 changes: 94 additions & 0 deletions pkg/universe.dagger.io/examples/todoapp/netlify.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package netlify

import (
"dagger.io/dagger"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
"universe.dagger.io/docker"
"universe.dagger.io/netlify"
)

dagger.#Plan & {
client: {
filesystem: {
".": read: {
contents: dagger.#FS
exclude: [
"README.md",
"build",
"netlify.cue",
"node_modules",
]
}
build: write: contents: actions.build.contents.output
}
env: {
APP_NAME: string
NETLIFY_TEAM: string
NETLIFY_TOKEN: dagger.#Secret
}
}
actions: {
deps: docker.#Build & {
steps: [
alpine.#Build & {
packages: {
bash: {}
yarn: {}
git: {}
}
},
docker.#Copy & {
contents: client.filesystem.".".read.contents
dest: "/src"
},
// bash.#Run is a superset of docker.#Run
// install yarn dependencies
bash.#Run & {
workdir: "/src"
mounts: "/cache/yarn": dagger.#Mount & {
dest: "/cache/yarn"
type: "cache"
contents: dagger.#CacheDir & {
id: "todoapp-yarn-cache"
}
}
script: contents: #"""
yarn config set cache-folder /cache/yarn
yarn install
"""#
},
]
}

test: bash.#Run & {
input: deps.output
workdir: "/src"
script: contents: #"""
yarn run test
"""#
}

build: {
run: bash.#Run & {
input: test.output
workdir: "/src"
script: contents: #"""
yarn run build
"""#
}

contents: dagger.#Subdir & {
input: run.output.rootfs
path: "/src/build"
}
}

deploy: netlify.#Deploy & {
contents: build.contents.output
site: client.env.APP_NAME
token: client.env.NETLIFY_TOKEN
team: client.env.NETLIFY_TEAM
}
}
}
38 changes: 38 additions & 0 deletions pkg/universe.dagger.io/examples/todoapp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "moz-todo-react",
"version": "0.1.0",
"private": true,
"homepage": "./",
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"gh-pages": "^3.2.3",
"nanoid": "^3.1.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --watchAll=false --passWithNoTests",
"gh-pages": "gh-pages -d build -u 'github-actions-bot <[email protected]>'",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file not shown.
43 changes: 43 additions & 0 deletions pkg/universe.dagger.io/examples/todoapp/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>My Todo app</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading