-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (78 loc) · 3.44 KB
/
Copy pathbuild-docker.yml
File metadata and controls
86 lines (78 loc) · 3.44 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
name: Docker Image CI
on:
push:
branches: ["main"]
# ensure that version tags also trigger a build, naming convention is `vX.Y.Z`
# make sure the naming convention is followed in tags.
tags:
- "v*"
pull_request:
branches: ["main"]
# permit manual trigger as well
workflow_dispatch:
jobs:
build:
# this only works on jabasai organisation and should be skipped otherwise
if: github.repository_owner == 'jabasai'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Git Checkout
uses: actions/checkout@v5
with:
fetch-depth: 1
# log in to GitHub Container Registry with correct permission
# only works within jabasai organisation and NOT on forks
- name: Docker Login GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# create a docker image name from the github repository name, ensuring lower case and no disallowed characters
- name: create docker image name from github name
id: docker-image-name
run: |
repo_name=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '. ' '-')
echo "image_name=$repo_name" >> $GITHUB_OUTPUT
# set the relevant docker tags and labels
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
org.opencontainers.image.version=${{ github.ref_name }}
images: |
ghcr.io/${{ steps.docker-image-name.outputs.image_name }}
flavor: |
latest=auto
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
- name: setup buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: .
file: ./.devcontainer/Dockerfile
platforms: linux/amd64 # add other platforms if needed
cache-from: type=gha
cache-to: type=gha,mode=max
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: final
build-args: |
BASE_IMAGE=ros:humble
GIT_REPO_VERSION=${{ github.ref_name }}
GIT_REPO_VERSION_DATE=${{ github.event.head_commit.timestamp }}