-
Notifications
You must be signed in to change notification settings - Fork 33
58 lines (48 loc) · 1.91 KB
/
automated_docker_release.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
name: Release image for local development environment
on:
push:
branches:
- master
- develop
env:
IMAGE_NAME: ${{ github.repository }}/${{ github.event.repository.name }}
jobs:
build:
name: Automated release fo Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nelonoel/[email protected]
- name: Build and tag the image for testing and release
run: >-
docker build .
--file Dockerfile
--tag docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME}
- name: Set release tag
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
run: echo "RELEASE_VERSION=$(printf -- '%s%s\n' $(cat .release-version) $([ ${BRANCH_NAME} = "develop" ] && printf -- '-%s-develop' ${GITHUB_RUN_ID} || echo ""))" >> $GITHUB_ENV
- name: Login to registry
run: >-
docker login
-u ${{ github.actor }}
-p ${{ secrets.GITHUB_TOKEN }}
docker.pkg.github.com
- name: Tag image with release version
run: >-
docker tag
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME}
docker.pkg.github.com/${IMAGE_NAME}:${{ env.RELEASE_VERSION }}
- name: Push release tag image to registry
run: >-
docker push docker.pkg.github.com/${IMAGE_NAME}:${{ env.RELEASE_VERSION }}
- name: Remove old releases
uses: snok/container-retention-policy@v2
with:
image-names: ${{ github.event.repository.name }}/*
cut-off: Four months ago UTC
timestamp-to-use: updated_at
account-type: org
org-name: sanger
keep-at-least: 5
skip-tags: latest, *[!develop] # This will DELETE any images where the tag contains ANY characters in "develop", excluding '!'
token: ${{ secrets.REMOVE_OLD_IMAGES }}