-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (46 loc) · 2.06 KB
/
scheduler-docker-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
rname: Scheduler Image CI
on:
push:
tags:
- 'scheduler-*' # Only trigger on tags that start with 'scheduler-'
branches:
- "main"
- "local"
pull_request:
branches:
- "main"
- "local"
jobs:
build-and-push:
if: startsWith(github.ref, 'refs/tags/scheduler-')
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USER_NAME }}" --password-stdin
- name: Build and tag the Docker image
id: build
run: |
TIMESTAMP=$(date +%s)
echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV
# Define the default tags for the main branch
TAGS="${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:latest"
ADDITIONAL_TAG="${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:$TIMESTAMP"
# If the branch is 'local', modify the tags
if [ "${{ github.ref }}" == "refs/heads/local" ]; then
TAGS="${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:local"
ADDITIONAL_TAG="${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:$TIMESTAMP-local"
fi
# Build the Docker image with the appropriate tags
docker build . --file Mostlylucid.SchedulerService/Dockerfile --tag $TAGS --tag $ADDITIONAL_TAG
- name: Push the Docker image to Docker Hub
run: |
# Push the appropriate tags based on the branch
if [ "${{ github.ref }}" == "refs/heads/local" ]; then
docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:local
docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:${{ env.TIMESTAMP }}-local
else
docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:latest
docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid-scheduler:${{ env.TIMESTAMP }}
fi