Skip to content

Commit dda0c4d

Browse files
committed
feat: Enable building container and pushing it
1 parent 46d0049 commit dda0c4d

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*.*.*' ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
env:
11+
REGISTRY: docker.io
12+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/ruuvicore
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Log in to Docker Hub
29+
if: github.event_name != 'pull_request'
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ secrets.DOCKERHUB_USERNAME }}
33+
password: ${{ secrets.DOCKERHUB_TOKEN }}
34+
35+
- name: Extract metadata (tags, labels)
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
# Development tag from main branch
42+
type=raw,value=dev,enable={{is_default_branch}}
43+
# Version tags from git tags (v1.2.3 -> 1.2.3, 1.2)
44+
type=semver,pattern={{version}}
45+
type=semver,pattern={{major}}.{{minor}}
46+
# Latest tag only on version tags
47+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
48+
flavor: |
49+
latest=false
50+
51+
- name: Build and push Docker image
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: .
55+
file: ./Dockerfile.crosscompile
56+
platforms: linux/arm/v7
57+
push: ${{ github.event_name != 'pull_request' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max
62+
63+
- name: Image digest
64+
run: echo ${{ steps.build.outputs.digest }}

0 commit comments

Comments
 (0)