forked from bilts/python-actions-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
42 lines (37 loc) · 1.4 KB
/
publish-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
name: Publish to DockerHub
on:
push:
branches:
- main
tags:
- v*
env:
REPOSITORY_USER: bilts
REGISTRY_PREFIX: harmonyservices/
REPOSITORY_PREFIX: bilts/python- # nasa/harmony-
# Or specify a full image name not derived from the repo
# IMAGE_NAME: custom-org/custom-image-name
jobs:
push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag "${GITHUB_REPOSITORY}" --label "runnumber=${GITHUB_RUN_ID}"
- name: Log into registry
run: echo "${{ secrets.DOCKERHUB }}" | docker login -u "${REPOSITORY_USER}" --password-stdin
- name: Push image
run: |
IMAGE_NAME=${IMAGE_NAME:-$(echo "${GITHUB_REPOSITORY}" | sed "s,^${REPOSITORY_PREFIX},${REGISTRY_PREFIX},g")}
# For tagged versions, translate e.g. "refs/tags/v1.2.3" -> "1.2.3"
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# For the main branch, use "latest" as the version
[ "$VERSION" == "main" ] && VERSION=latest
IMAGE_ID="${IMAGE_NAME}:${VERSION}"
echo "Pushing ${IMAGE_ID}"
docker tag "${GITHUB_REPOSITORY}" "${IMAGE_ID}"
docker push "${IMAGE_ID}"