-
Notifications
You must be signed in to change notification settings - Fork 7
161 lines (143 loc) · 4.99 KB
/
build-pixi-image.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Build and Push Docker Image
on:
workflow_call:
inputs:
working_directory:
type: string
description: What directory should the image be built from
required: true
image_name:
type: string
description: Name of Docker image
required: true
image_tag:
type: string
description: Tag for Docker image
required: true
push_image:
type: boolean
description: Should the image be pushed to the Github Container Registry
required: false
default: false
secrets:
GH_TOKEN:
description: Github access token
required: false
SLACK_WEBHOOK_URL:
description: Slack webhook URL to send messages to
required: false
outputs:
image_name:
description: Fully qualified image name
value: ${{ jobs.build-image.outputs.image_name}}
image_ref:
description: Docker image reference
value: ${{ jobs.build-image.outputs.image_ref }}
workflow_dispatch:
inputs:
working_directory:
type: string
description: What directory should the image be built from
required: true
image_name:
type: string
description: Name of Docker image
required: true
image_tag:
type: string
description: Tag for Docker image
required: true
push_image:
type: boolean
description: Should the image be pushed to the Github Container Registry
required: false
default: false
jobs:
build-image:
runs-on: ubuntu-22.04
name: Build and push image
timeout-minutes: 30
outputs:
image_name: ${{ steps.env_var.outputs.image_name }}
image_ref: ${{ steps.env_var.outputs.image_ref }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ohw-docker-buildx-${{ inputs.image_name }}-${{ github.sha }}
restore-keys: |
ohw-docker-buildx-${{ inputs.image_name }}
- name: Set Job Environment Variables
id: env_var
run: |
SHA7="${GITHUB_SHA::7}"
DOCKER_TAG=$SHA7
IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/${{ inputs.image_name }}"
echo "DOCKER_TAG=${{ inputs.image_tag }}" >> $GITHUB_ENV
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
echo "::set-output name=image_name::${IMAGE_NAME})"
echo "::set-output name=image_ref::${DOCKER_TAG})"
- name: Build Docker Image
uses: docker/[email protected]
with:
tags: |
${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
push: false
load: true
context: ${{ inputs.working_directory }}
- name: Docker image sizes
run: |
docker images | grep ${{ env.IMAGE_NAME }}
echo "### Image sizes" >> $GITHUB_STEP_SUMMARY
docker images | grep ${{ env.IMAGE_NAME }} >> $GITHUB_STEP_SUMMARY
- name: Export Full Conda Environment
run: |
docker run ${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} pixi list > conda-packages.txt
echo "### Conda Environment" >> $GITHUB_STEP_SUMMARY
cat conda-packages.txt >> $GITHUB_STEP_SUMMARY
- name: Archive Conda Package List
uses: actions/upload-artifact@v4
with:
name: conda-packages
path: conda-packages.txt
- name: "Log into GitHub Container Registery"
uses: docker/[email protected]
if: ${{ inputs.push_image}}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
- name: Push Docker Image to GitHub Container Registry
if: ${{ inputs.push_image }}
run: docker push ${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}
- name: Notify on newly built image
if: ${{ inputs.push_image }}
uses: slackapi/[email protected]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"text": "Built image ${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}. Maybe let 2i2c know?",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Built image `${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}`. Maybe let 2i2c know?"
}
}
]
}
- name: Move Docker Cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache