Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit 6f94214

Browse files
authored
Merge pull request #14 from onmetal/feature/docker-action
Use docker actions for image builds
2 parents 105e644 + fb43531 commit 6f94214

File tree

3 files changed

+44
-32
lines changed

3 files changed

+44
-32
lines changed

.github/workflows/publish-docker.yml

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,36 @@ on:
1414
- 'docs/**'
1515
- '**/*.md'
1616

17-
env:
18-
IMAGE_NAME: template-operator
19-
2017
jobs:
21-
test:
22-
runs-on: ubuntu-latest
23-
steps:
24-
- uses: actions/checkout@v2
25-
- name: Run test build
26-
run: |
27-
docker build . --file Dockerfile
28-
push:
29-
# Ensure test job passes before pushing image.
30-
needs: test
31-
18+
buildAndPush:
3219
runs-on: ubuntu-latest
33-
if: github.event_name == 'push'
3420
steps:
3521
- uses: actions/checkout@v2
36-
- name: Build image
37-
run: docker build . --file Dockerfile --tag image
38-
- name: Login to registry
39-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
40-
- name: Push image
41-
run: |
42-
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
43-
# Strip git ref prefix from version
44-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
45-
# Strip "v" prefix from tag name
46-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
47-
# Use Docker `latest` tag convention
48-
[ "$VERSION" == "main" ] && VERSION=latest
49-
echo IMAGE_ID=$IMAGE_ID
50-
echo VERSION=$VERSION
51-
docker tag image $IMAGE_ID:$VERSION
52-
docker push $IMAGE_ID:$VERSION
22+
- uses: docker/metadata-action@v3
23+
with:
24+
images: |
25+
ghcr.io/${{ github.repository_owner }}/template-operator
26+
tags: |
27+
type=semver,pattern={{version}}
28+
type=sha
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v1
31+
with:
32+
platforms: all
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v1
35+
- name: Login to GHCR
36+
if: github.event_name != 'pull_request'
37+
uses: docker/login-action@v1
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
- name: Build and push
43+
uses: docker/build-push-action@v2
44+
with:
45+
context: .
46+
platforms: linux/amd64,linux/arm64
47+
push: ${{ github.event_name != 'pull_request' }}
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}

controllers/template_controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,18 @@ func (r *TemplateReconciler) deleteWatches(key client.ObjectKey) error {
587587
}
588588

589589
func (r *TemplateReconciler) reconcile(ctx context.Context, logger logr.Logger, template *templatev1alpha1.Template) (ctrl.Result, error) {
590+
if err := r.applyWatches(template); err != nil {
591+
if err := r.updateStatus(ctx, template,
592+
nil,
593+
corev1.ConditionUnknown,
594+
"CannotApplyWatches",
595+
fmt.Sprintf("Applying watches resulted in an error: %v", err),
596+
); err != nil {
597+
logger.Error(err, "Error updating status.")
598+
}
599+
return ctrl.Result{}, fmt.Errorf("error applying watches: %w", err)
600+
}
601+
590602
objs, err := r.engine.Render(ctx, template)
591603
if err != nil {
592604
if err := r.updateStatus(ctx, template,

kubectl-template_operator/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ func RunRender(ctx context.Context, namespace, name, filename string) error {
166166
}
167167

168168
tmpl, err := getOrReadTemplate(ctx, c, namespace, name, filename)
169+
if err != nil {
170+
return fmt.Errorf("could not obtain template: %w", err)
171+
}
169172

170173
objs, err := template.NewEngine(c, scheme).Render(ctx, tmpl)
171174
if err != nil {

0 commit comments

Comments
 (0)