-
Notifications
You must be signed in to change notification settings - Fork 9
102 lines (88 loc) · 2.96 KB
/
build.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
name: build
on:
push:
branches: [ main ]
# Run when container or environment is changed
paths:
- containers/dockerfile_cpu
- environment.yml
# Allows workflow to be manually triggered
workflow_dispatch:
defaults:
run:
shell: bash -l {0}
env:
REGISTRY: ghcr.io
IMAGE_NAME: cmelab/grits
DOCKERFILE: containers/dockerfile_cpu
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Get Latest Version
id: latest-version
run: |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo $LATEST_TAG
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
# slice off the v, ie v0.7.2 -> 0.7.2
VERSION=${LATEST_TAG:1}
echo $VERSION
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Print Latest Version
run: echo ${{ steps.latest-version.outputs.VERSION }}
- name: Create fully qualified image registry path
id: fqirp
run: |
FQIRP=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.latest-version.outputs.VERSION }}
echo "FQIRP=$FQIRP" >> $GITHUB_OUTPUT
- name: Print FQIRP
run: echo ${{ steps.fqirp.outputs.FQIRP }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag,enable=true,priority=600
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{version}}
type=sha
${{ steps.latest-version.outputs.VERSION }}
- name: Build Docker Image
uses: docker/build-push-action@v4
with:
context: .
file: ${{ env.DOCKERFILE }}
load: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.latest-version.outputs.VERSION }}
- name: Test image
run: |
docker run --rm ${{ steps.fqirp.outputs.FQIRP }} python -c "import grits; print(grits.__version__)"
- name: Push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: ${{ env.DOCKERFILE }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.latest-version.outputs.VERSION }}