Skip to content

Commit c45b7a5

Browse files
committed
Build backend into docker image and push to GH registry
1 parent ba76180 commit c45b7a5

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
paths-ignore:
9+
- 'docs/**'
10+
- 'README.md'
11+
- 'zensical.toml'
12+
release:
13+
types: [published]
14+
workflow_dispatch:
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
build-and-push:
22+
name: Build and Push Docker Image
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to GitHub Container Registry
36+
if: github.event_name != 'pull_request'
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Extract metadata
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
tags: |
49+
# Tag with 'dev' on push to main
50+
type=raw,value=dev,enable={{is_default_branch}}
51+
# Tag with version number on release
52+
type=semver,pattern={{version}}
53+
# Tag with 'latest' on release (not pre-release)
54+
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
55+
labels: |
56+
org.opencontainers.image.title=Hermes Backend
57+
org.opencontainers.image.description=NASA telemetry and commanding system backend
58+
org.opencontainers.image.vendor=Jet Propulsion Laboratory
59+
60+
- name: Build and push Docker image
61+
uses: docker/build-push-action@v6
62+
with:
63+
context: .
64+
file: docker/Dockerfile
65+
push: ${{ github.event_name != 'pull_request' }}
66+
tags: ${{ steps.meta.outputs.tags }}
67+
labels: ${{ steps.meta.outputs.labels }}
68+
cache-from: type=gha
69+
cache-to: type=gha,mode=max
70+
platforms: linux/amd64,linux/arm64
71+
72+
- name: Image digest
73+
if: github.event_name != 'pull_request'
74+
run: echo "Image pushed with digest ${{ steps.meta.outputs.digest }}"

0 commit comments

Comments
 (0)