-
Notifications
You must be signed in to change notification settings - Fork 27
50 lines (42 loc) · 1.75 KB
/
push-images.yaml
File metadata and controls
50 lines (42 loc) · 1.75 KB
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
name: Push images
on:
push:
branches:
- master
workflow_dispatch:
env:
IMAGE_NAME: pypsa/eur-dev-env
jobs:
push-image:
name: dev-env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 'Get last commit that changed pixi env or Dockerfile'
run: |
hash_last_changed=$(git log -1 --pretty=format:%H -- pixi.toml pixi.lock docker/dev-env/Dockerfile)
echo "hash_last_changed=$hash_last_changed" >> $GITHUB_ENV
- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: 'Build new image' # only build if the locked envs file was modified
if: env.hash_last_changed == github.sha || github.event_name == 'workflow_dispatch'
run: |
docker build . --file docker/dev-env/Dockerfile --tag ghcr.io/${{ env.IMAGE_NAME }}:${{ github.sha }}
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ github.sha }}
# Add latest tag if on main branch
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
docker tag ghcr.io/${{ env.IMAGE_NAME }}:${{ github.sha }} ghcr.io/${{ env.IMAGE_NAME }}:latest
docker push ghcr.io/${{ env.IMAGE_NAME }}:latest
fi
- name: 'Add SHA tag to existing image' # when rebuild is not needed
if: env.hash_last_changed != github.sha
run: |-
docker pull ghcr.io/${{ env.IMAGE_NAME }}:${{ env.hash_last_changed }}
docker tag ghcr.io/${{ env.IMAGE_NAME }}:${{ env.hash_last_changed }} ghcr.io/${{ env.IMAGE_NAME }}:${{ github.sha }}
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ github.sha }}