forked from Materials-Consortia/optimade-python-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·101 lines (85 loc) · 3.45 KB
/
cd_container_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
name: Build and Publish Container Image
on:
workflow_call:
inputs:
release:
description: 'Whether or not this is a release.'
default: false
required: false
type: boolean
checkout_ref:
description: 'The git ref to checkout and use as source.'
default: master
required: false
type: string
jobs:
publish_container_image:
name: Publish Container image on GH Container Registry
if: github.repository_owner == 'Materials-Consortia'
runs-on: ubuntu-latest
env:
IMAGE_NAME: optimade
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
ref: ${{ inputs.checkout_ref }}
- name: Retrieve version
run: |
# Get current OPTIMADE version from optimade/__init__.py
regex="^__version__ = (\"|')(.*)(\"|')$"
while IFS="" read -r line || [ -n "${line}" ]; do
if [[ "${line}" =~ $regex ]]; then
VERSION="${BASH_REMATCH[2]}"
fi
done < optimade/__init__.py
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo VERSION=${VERSION}
- name: Set source ref
run: |
if [[ "${{ inputs.release }}" == "true" ]]; then
# Use tag for metadata instead of commit SHA
SOURCE_REF=v${{ env.VERSION }}
else
SOURCE_REF=$(git rev-parse HEAD)
fi
echo "SOURCE_REF=${SOURCE_REF}" >> $GITHUB_ENV
echo SOURCE_REF=${SOURCE_REF}
- name: Build image
run: |
docker build \
--file Dockerfile \
--tag "${IMAGE_NAME}" \
--label "gh_actions_runnumber=${GITHUB_RUN_ID}" \
--label "org.openctonainers.image.title=OPTIMADE" \
--label "org.opencontainers.image.description=A server implementation for serving an OPTIMADE API." \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository }}/tree/${{ env.SOURCE_REF }}" \
--label "org.opencontainers.image.documentation=https://github.com/${{ github.repository }}/blob/${{ env.SOURCE_REF }}/README.md" \
--label "org.opencontainers.image.licenses=MIT" \
--label "org.opencontainers.image.url=https://github.com/${{ github.repository }}/pkgs/container/${IMAGE_NAME}" \
--label "org.opencontainers.image.vendor=${{ github.repository_owner }}" \
--label "org.opencontainers.image.version=${{ env.VERSION }}" \
--label "org.opencontainers.image.base.name=docker.io/library/python:3.10-slim" \
.
- name: Create full image ID and tag with 'develop'
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}
# Change all uppercase to lowercase
IMAGE_ID=$(echo ${IMAGE_ID} | tr '[A-Z]' '[a-z]')
echo "IMAGE_ID=${IMAGE_ID}" >> $GITHUB_ENV
echo IMAGE_ID=${IMAGE_ID}
# Tag with "develop"
docker tag ${IMAGE_NAME} ${IMAGE_ID}:develop
- name: Tag with version and `latest` - if it's a release
if: inputs.release
run: |
docker tag ${IMAGE_NAME} ${{ env.IMAGE_ID }}:${{ env.VERSION }}
docker tag ${IMAGE_NAME} ${{ env.IMAGE_ID }}:latest
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
docker image inspect ${IMAGE_NAME}
docker push --all-tags ${{ env.IMAGE_ID }}