forked from jmpsec/osctrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
112 lines (101 loc) · 4.1 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: "Build Osctrl Docker images"
description: "Build Osctrl Docker images"
inputs:
go_os:
required: true
description: Define the OS to compile binary for - https://pkg.go.dev/internal/goos
go_arch:
required: true
description: Define the architecture to compile binary for - https://pkg.go.dev/internal/goarch
osctrl_component:
required: true
description: Define the osctrl component to compile
commit_sha:
required: true
description: Define the SHA1 git commit hash
docker_hub_org:
required: true
description: Pass DockerHub org to action
docker_hub_username:
required: true
description: Pass DockerHub username to action
docker_hub_access_token:
required: true
description: Pass DockerHub access token to action
outputs:
docker_image_digest:
description: Dockerhub image digest
value: ${{ toJson(steps.docker_build.outputs.digest) }}
runs:
using: "composite"
steps:
########################### Checkout code ###########################
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 2
########################### Download osctrl binary ###########################
- name: Download osctrl binary
uses: actions/[email protected]
with:
name: osctrl-${{ inputs.osctrl_component }}-${{ inputs.commit_sha }}-${{ inputs.go_os }}-${{ inputs.go_arch }}.bin
########################### Copy binary to prepare for Docker ###########################
- name: Copy binary to prepare for Docker
shell: bash
run: |
cp \
osctrl-${{ inputs.osctrl_component }}-${{ inputs.commit_sha }}-${{ inputs.go_os }}-${{ inputs.go_arch }}.bin \
osctrl-${{ inputs.osctrl_component }}-${{ inputs.go_os }}-${{ inputs.go_arch }}.bin
########################### Add meta data for containers ###########################
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.docker_hub_org }}/osctrl-${{ inputs.osctrl_component }}
labels: |
org.opencontainers.image.title=osctrl-${{ inputs.osctrl_component }}
tags: |
type=sha,prefix=,format=short
type=match,pattern=v(.*),group=1
########################### Log into Dockerhub ###########################
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ inputs.docker_hub_username }}
password: ${{ inputs.docker_hub_access_token }}
# ########################### Setup QEMU ###########################
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
########################### Setup Docker ###########################
- name: Set up Docker Buildx
uses: docker/[email protected]
########################### Build and Push Docker images ###########################
- name: Build and push
uses: docker/[email protected]
id: docker_build
with:
context: .
file: ./deploy/cicd/docker/Dockerfile-osctrl-${{ inputs.osctrl_component }}
push: true
labels: ${{ steps.meta.outputs.labels }}
platforms: "${{ inputs.go_os }}/${{ inputs.go_arch }}"
outputs: type=image,name=${{ inputs.docker_hub_org }}/osctrl-${{ inputs.osctrl_component }},push-by-digest=true,name-canonical=true,push=true
build-args: |
COMPONENT=${{ inputs.osctrl_component }}
GOOS=${{ inputs.go_os }}
GOARCH=${{ inputs.go_arch }}
########################### Export image digest to tmp ###########################
- name: Export digest
shell: bash
run: |
mkdir -p /tmp/digests
digest="${{ steps.docker_build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
########################### Upload digest ###########################
- name: Upload digest
uses: actions/[email protected]
with:
name: digests-osctrl-${{ inputs.osctrl_component }}-${{ inputs.go_os }}-${{ inputs.go_arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1