Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6cd398

Browse files
committed
Add a container building workflow
1 parent 34e5267 commit d6cd398

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

.github/workflows/build-image.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
3+
name: Create and publish a container image
4+
5+
on:
6+
push
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
CADDY_VERSION: "2.4.6"
12+
13+
jobs:
14+
build-and-push-image:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v2
23+
24+
- name: Log in to the Container registry
25+
uses: docker/[email protected]
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Extract metadata (tags, labels)
32+
id: meta
33+
uses: docker/[email protected]
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
36+
37+
- name: Build and push container image
38+
uses: docker/[email protected]
39+
with:
40+
context: .
41+
file: ./Containerfile
42+
build-args: |
43+
CADDY_VERSION=${{ env.CADDY_VERSION }}
44+
push: true
45+
tags: ${{ steps.meta.outputs.tags }}
46+
labels: ${{ steps.meta.outputs.labels }}

Containerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ARG CADDY_VERSION=latest
2+
FROM docker.io/library/caddy:${CADDY_VERSION}-builder AS builder
3+
4+
RUN xcaddy build
5+
6+
FROM docker.io/library/caddy:${CADDY_VERSION}
7+
8+
COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
RUNTIME ?= podman
2+
CADDY_IMAGE ?= caddy-mpl
23
CADDY_VERSION ?= 2.4.6
34

45
serve:
@@ -8,11 +9,17 @@ serve:
89
-v $$PWD/Caddyfile:/etc/caddy/Caddyfile:ro,Z \
910
-e SITE_DIR=/srv \
1011
-p 2015:2015 \
11-
docker.io/library/caddy:$(CADDY_VERSION) \
12+
$(CADDY_IMAGE):$(CADDY_VERSION) \
1213
caddy run --config /etc/caddy/Caddyfile --watch
1314

15+
image:
16+
$(RUNTIME) build \
17+
--build-arg=CADDY_VERSION=$(CADDY_VERSION) \
18+
-t $(CADDY_IMAGE):$(CADDY_VERSION) \
19+
-f Containerfile
20+
1421
fmt:
1522
$(RUNTIME) run --rm -it \
1623
-v $$PWD/Caddyfile:/etc/caddy/Caddyfile:Z \
17-
docker.io/library/caddy:$(CADDY_VERSION) \
24+
$(CADDY_IMAGE):$(CADDY_VERSION) \
1825
caddy fmt --overwrite /etc/caddy/Caddyfile

0 commit comments

Comments
 (0)