Skip to content

Commit 993f33e

Browse files
Make action fully equivalent to the okteto build command (#18)
* refactor: remove deprecated global argument Signed-off-by: Teresa Romero <[email protected]> * refactor: fix file argument Signed-off-by: Teresa Romero <[email protected]> * refactor: include tag param into Readme and entrypoint Signed-off-by: Teresa Romero <[email protected]> * refactor: include path into command Signed-off-by: Teresa Romero <[email protected]> * docs: README update Signed-off-by: Teresa Romero <[email protected]> * refactor: add buildargs support Signed-off-by: Teresa Romero <[email protected]> * docs: README update based on #17 Signed-off-by: Teresa Romero <[email protected]> * refactor: fix build-args support Signed-off-by: Teresa Romero <[email protected]> * refactor: support other flags for build command Signed-off-by: Teresa Romero <[email protected]> * Apply suggestions from code review Co-authored-by: Andrea Falzetti <[email protected]> --------- Signed-off-by: Teresa Romero <[email protected]> Co-authored-by: Andrea Falzetti <[email protected]>
1 parent ff46440 commit 993f33e

File tree

3 files changed

+191
-52
lines changed

3 files changed

+191
-52
lines changed

README.md

+113-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# GitHub Actions for Okteto Cloud
22

33
## Automate your development workflows using Github Actions and Okteto Cloud
4+
45
GitHub Actions gives you the flexibility to build an automated software development workflows. With GitHub Actions for Okteto Cloud you can create workflows to build, deploy and update your applications in [Okteto Cloud](https://cloud.okteto.com).
56

67
Get started today with a [free Okteto Cloud account](https://cloud.okteto.com)!
@@ -11,20 +12,47 @@ You can use this action to build images from an [Okteto Manifest](https://www.ok
1112

1213
## Inputs
1314

15+
### `tag`
16+
17+
Name and optionally a tag in the `name:tag` format for the build. When `file` points to a `Dockerfile`, in order to push the image to a registry, a `tag` is required. Otherwise, the build would be done but no image will be pushed to the registry.
18+
1419
### `file`
1520

16-
The path to the Okteto Manifest. Default `"okteto.yml"`.
17-
Name of the Dockerfile. Default `"Dockerfile"`.
21+
The relative path to the Okteto Manifest.
22+
23+
> You can also use this input to point to a Dockerfile. In this mode, okteto build will ignore your Okteto manifest, and directly build the image defined in the Dockerfile. Use this to build images that are not defined on your Okteto manifest.
24+
25+
### `path`
26+
27+
Service from the Okteto Manifest to build. You can select the service to build providing the `path`, otherwise all images at the Okteto Manifest build definition would be build.
28+
29+
When repository does not have an Okteto Manifest or `Dockerfile` is provided at `file`, `path` is the execution path of the action. .
30+
31+
### `buildargs`
1832

19-
### `global`
33+
A list of comma-separated build arguments.
2034

21-
When true will make the image available to everyone in your team. Default `false`.
22-
Only admins can push images to the global registry.
35+
### `no-cache`
2336

37+
Set to "true" when no cache should be used when building the image
38+
39+
### `cache-from`
40+
41+
A list of comma-separated images where cache should be imported from.
42+
43+
### `export-cache`
44+
45+
A list of comma-separated images where cache should be exported to.
46+
47+
### `secrets`
48+
49+
A list of semi-colon secrets. Each with format: id=mysecret,src=/local/secret
2450

2551
## Example usage
2652

27-
This example runs the context action and then builds and pushes an image.
53+
### Build and push images for all services described at an Okteto Manifest
54+
55+
This example runs the context action `okteto/context@latest` and then builds and pushes an image. A valid Okteto Manifest should exist at the repository.
2856

2957
```yaml
3058
# File: .github/workflows/workflow.yml
@@ -33,48 +61,99 @@ on: [push]
3361
name: example
3462

3563
jobs:
64+
devflow:
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: okteto/context@latest
68+
with:
69+
token: ${{ secrets.OKTETO_TOKEN }}
70+
71+
- name: "Build"
72+
uses: okteto/build@latest
73+
```
74+
75+
### Build and push images for single service described in the Okteto Manifest
3676
77+
This example runs the context action `okteto/context@latest` and then builds and pushes the image for the service `service`. A valid Okteto Manifest should exist at the repository.
78+
79+
```yaml
80+
# File: .github/workflows/workflow.yml
81+
on: [push]
82+
83+
name: example
84+
85+
jobs:
3786
devflow:
3887
runs-on: ubuntu-latest
3988
steps:
40-
41-
- uses: okteto/context@latest
42-
with:
43-
token: ${{ secrets.OKTETO_TOKEN }}
44-
45-
- name: "Build"
46-
uses: okteto/build@latest
89+
- name: "Context Setup"
90+
uses: okteto/context@latest
91+
with:
92+
token: ${{ secrets.OKTETO_TOKEN }}
93+
94+
- name: "Build"
95+
uses: okteto/build@latest
96+
with:
97+
path: service
4798
```
4899

100+
### Build and push images that are not defined in your Okteto manifest.
101+
102+
This example sets the context, and then builds an image that is not defined in the Okteto Manifest.
103+
104+
```yaml
105+
# File: .github/workflows/workflow.yml
106+
on: [push]
107+
108+
name: example
109+
110+
jobs:
111+
devflow:
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: "Context Setup"
115+
uses: okteto/context@latest
116+
with:
117+
token: ${{ secrets.OKTETO_TOKEN }}
118+
119+
- name: "Build"
120+
uses: okteto/build@latest
121+
with:
122+
tag: myapp-backend:latest
123+
file: Dockerfile
124+
path: backend
125+
```
126+
127+
If `tag` is not provided, the image won't be pushed to the registry.
128+
49129
## Advanced usage
50130

51-
### Custom Certification Authorities or Self-signed certificates
131+
### Custom Certification Authorities or Self-signed certificates
52132

53-
You can specify a custom certificate authority or a self-signed certificate by setting the `OKTETO_CA_CERT` environment variable. When this variable is set, the action will install the certificate in the container, and then execute the action.
133+
You can specify a custom certificate authority or a self-signed certificate by setting the `OKTETO_CA_CERT` environment variable. When this variable is set, the action will install the certificate in the container, and then execute the action.
54134

55-
Use this option if you're using a private Certificate Authority or a self-signed certificate in your [Okteto Enterprise](http://okteto.com/enterprise) instance. We recommend that you store the certificate as an [encrypted secret](https://docs.github.com/en/actions/reference/encrypted-secrets), and that you define the environment variable for the entire job, instead of doing it on every step.
135+
Use this option if you're using a private Certificate Authority or a self-signed certificate in your [Okteto Enterprise](http://okteto.com/enterprise) instance. We recommend that you store the certificate as an [encrypted secret](https://docs.github.com/en/actions/reference/encrypted-secrets), and that you define the environment variable for the entire job, instead of doing it on every step.
56136

137+
```yaml
138+
# File: .github/workflows/workflow.yml
139+
on: [push]
57140
58-
```yaml
59-
# File: .github/workflows/workflow.yml
60-
on: [push]
141+
name: example
61142
62-
name: example
143+
jobs:
144+
devflow:
145+
runs-on: ubuntu-latest
146+
env:
147+
OKTETO_CA_CERT: ${{ secrets.OKTETO_CA_CERT }}
148+
steps:
149+
- name: checkout
150+
uses: actions/checkout@master
63151
64-
jobs:
65-
devflow:
66-
runs-on: ubuntu-latest
67-
env:
68-
OKTETO_CA_CERT: ${{ secrets.OKTETO_CA_CERT }}
69-
steps:
152+
- name: "Context Setup"
153+
uses: okteto/context@latest
154+
with:
155+
token: ${{ secrets.OKTETO_TOKEN }}
70156
71-
- name: checkout
72-
uses: actions/checkout@master
73-
74-
- uses: okteto/context@latest
75-
with:
76-
token: ${{ secrets.OKTETO_TOKEN }}
77-
78157
- name: "Build"
79158
uses: okteto/build@latest
80-
```
159+
```

action.yml

+19-9
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@ name: 'Okteto Build'
22
description: 'Build an image from a Dockerfile using Okteto Cloud'
33
inputs:
44
tag:
5-
description: 'Name and tag in the "name:tag" format'
5+
description: 'Name and tag for the image in the "name:tag" format'
66
required: false
77
file:
8-
description: 'Name of the Dockerfile (Default is "Dockerfile")'
8+
description: 'Name of the file for the Okteto Manifest or Dockerfile.'
99
required: false
10-
default: 'Dockerfile'
1110
path:
12-
description: 'The path'
11+
description: 'Path where the build is run.'
1312
required: false
14-
default: '.'
1513
buildargs:
1614
description: 'Use buildargs when you want to pass a list of environment variables as build-args'
1715
required: false
18-
global:
19-
description: 'Use global when you want to make the image availbale to everyone in your team'
16+
no-cache:
17+
description: 'Do not use cache when building the image'
18+
required: false
19+
cache-from:
20+
description: 'List of cache source images'
21+
required: false
22+
export-cache:
23+
description: 'List of exported cache images'
24+
required: false
25+
secrets:
26+
description: 'Secret files exposed to the build. Format: id=mysecret,src=/local/secret'
2027
required: false
21-
default: false
2228
runs:
2329
using: 'docker'
2430
image: 'Dockerfile'
@@ -27,7 +33,11 @@ runs:
2733
- ${{ inputs.file }}
2834
- ${{ inputs.path }}
2935
- ${{ inputs.buildargs }}
30-
- ${{ inputs.global }}
36+
- ${{ inputs.no-cache }}
37+
- ${{ inputs.cache-from }}
38+
- ${{ inputs.export-cache }}
39+
- ${{ inputs.secrets }}
40+
3141
branding:
3242
color: 'green'
3343
icon: 'layers'

entrypoint.sh

+59-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,74 @@
11
#!/bin/sh
22
set -e
33

4+
tag=$1
45
file=$2
5-
global=$5
6-
7-
BUILDPARAMS=""
6+
path=$3
7+
buildargs=$4
8+
nocache=$5
9+
cachefrom=$6
10+
exportcache=$7
11+
secrets=$8
812

913
if [ ! -z "$OKTETO_CA_CERT" ]; then
1014
echo "Custom certificate is provided"
1115
echo "$OKTETO_CA_CERT" > /usr/local/share/ca-certificates/okteto_ca_cert.crt
1216
update-ca-certificates
1317
fi
1418

15-
params=$(eval echo --progress plain -f "$file")
19+
# if path is ".", override value to empty
20+
# Okteto CLI will run on root
21+
if [ "$path" = "." ]; then
22+
path=""
23+
fi
24+
25+
command="build"
1626

17-
if [ "$global" = "true" ]; then
18-
params="${params} --global"
27+
if [ ! -z $path ]; then
28+
command=$(eval echo "$command" "$path")
1929
fi
2030

21-
params=$(eval echo "$params")
31+
params=$(eval echo --progress plain)
32+
33+
if [ ! -z $tag ]; then
34+
params=$(eval echo "$params" -t "$tag")
35+
fi
36+
37+
if [ ! -z $file ]; then
38+
params=$(eval echo "$params" -f "$file")
39+
fi
40+
41+
if [ ! -z $buildargs ]; then
42+
IFS=',' read -ra ARG <<< "$buildargs"
43+
for i in "${ARG[@]}"; do
44+
params=$(eval echo "$params" --build-arg "$i")
45+
done
46+
fi
47+
48+
if [ "$nocache" = "true" ]; then
49+
params="${params} --no-cache"
50+
fi
51+
52+
if [ ! -z $cachefrom ]; then
53+
IFS=',' read -ra CACHEF <<< "$cachefrom"
54+
for i in "${CACHEF[@]}"; do
55+
params=$(eval echo "$params" --cache-from "$i")
56+
done
57+
fi
58+
59+
if [ ! -z $exportcache ]; then
60+
IFS=',' read -ra ECACHE <<< "$exportcache"
61+
for i in "${ECACHE[@]}"; do
62+
params=$(eval echo "$params" --export-cache "$i")
63+
done
64+
fi
65+
66+
if [ ! -z $secrets ]; then
67+
IFS=';' read -ra SECRET <<< "$secrets"
68+
for i in "${SECRET[@]}"; do
69+
params=$(eval echo "$params" --secret "$i")
70+
done
71+
fi
2272

23-
echo running: okteto build $params
24-
okteto build $params
73+
echo running: okteto $command $params
74+
okteto $command $params

0 commit comments

Comments
 (0)