-
Notifications
You must be signed in to change notification settings - Fork 57
91 lines (82 loc) · 2.96 KB
/
docker-release.yml
File metadata and controls
91 lines (82 loc) · 2.96 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
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
name: Build and Push emoncms Docker Image
on:
pull_request:
workflow_dispatch:
inputs:
php_version:
description: 'php_version'
required: true
type: string
default: '8.4'
emoncms_src:
description: 'emoncms_src'
required: true
type: string
default: 'emoncms/emoncms'
branch:
description: 'branch'
required: true
type: string
default: 'stable'
env:
PHP_VERSION: ${{ inputs.php_version || '8.4' }}
EMONCMS_SRC: ${{ inputs.emoncms_src || 'emoncms/emoncms' }}
EMONCMS_BRANCH: ${{ inputs.branch || 'stable' }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for Docker Hub credentials
id: check_dockerhub
run: |
if [ -n "${{ secrets.DOCKER_USERNAME }}" ] && [ -n "${{ secrets.DOCKER_PASSWORD }}" ]; then
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
fi
- name: Log in to Docker Hub
if: steps.check_dockerhub.outputs.available == 'true' && github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to GitHub Container Registry
if: steps.check_dockerhub.outputs.available != 'true' || github.event_name == 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get emoncms version
id: emoncms_version
run: |
wget https://raw.githubusercontent.com/${{ env.EMONCMS_SRC }}/${{ env.EMONCMS_BRANCH }}/version.json
version=$(cat version.json | jq --raw-output '.version')
echo $version
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Set image tags
id: tags
run: |
VERSION="${{ steps.emoncms_version.outputs.version }}"
if [ "${{ github.event_name }}" = "pull_request" ]; then
TAGS="ghcr.io/${{ github.repository_owner }}/emoncms:pr-${{ github.event.number }}"
elif [ "${{ steps.check_dockerhub.outputs.available }}" = "true" ]; then
TAGS="openenergymonitor/emoncms:latest,openenergymonitor/emoncms:${VERSION}"
else
TAGS="ghcr.io/${{ github.repository_owner }}/emoncms:latest,ghcr.io/${{ github.repository_owner }}/emoncms:${VERSION}"
fi
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./web
build-args: |
"BUILD_FROM=php:${{ env.PHP_VERSION }}-apache"
"EMONCMS_SRC=https://github.com/${{ env.EMONCMS_SRC }}"
"BRANCH=${{ env.EMONCMS_BRANCH }}"
push: true
tags: ${{ steps.tags.outputs.tags }}