-
Notifications
You must be signed in to change notification settings - Fork 59
add Dockerfile and GitHub action for building image #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Docker | ||
|
||
on: | ||
push: | ||
# push events will publish a new image, so only trigger on main branch or semver tags. | ||
branches: ["main"] | ||
tags: ["v*"] | ||
pull_request: | ||
# Run the workflow on pull_request events to ensure we can still build the image. | ||
# We only publish the image on push events (see if statements in steps below). | ||
branches: ["main"] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 | ||
|
||
- name: Log into registry ${{ env.REGISTRY }} | ||
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 | ||
if: github.event_name == 'push' | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
|
||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0 | ||
with: | ||
context: . | ||
push: ${{ github.event_name == 'push' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64,linux/arm/v7 | ||
|
||
# Sign the Docker image | ||
- name: Install cosign | ||
if: github.event_name == 'push' | ||
uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb #v3.8.2 | ||
- name: Sign the published Docker image | ||
if: github.event_name == 'push' | ||
run: cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
ARG GO_VERSION=1.24 | ||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine as build | ||
Check warning on line 2 in Dockerfile
|
||
|
||
WORKDIR /work | ||
|
||
# Install git so that go build populates the VCS details in build info, which | ||
# is then reported to Tailscale in the node version string. | ||
RUN apk --no-cache add git=2.47.2-r0 | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
ARG TARGETOS TARGETARCH TARGETVARIANT | ||
RUN \ | ||
if [ "${TARGETARCH}" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \ | ||
export GOARM="${TARGETVARIANT#v}"; \ | ||
fi; \ | ||
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -v ./cmd/caddy | ||
|
||
# From https://github.com/caddyserver/caddy-docker/blob/master/2.10/alpine/Dockerfile | ||
FROM alpine:3.21 | ||
|
||
RUN mkdir -p \ | ||
/config/caddy \ | ||
/data/caddy \ | ||
/etc/caddy \ | ||
/usr/share/caddy | ||
|
||
COPY --from=build /work/caddy /usr/bin/caddy | ||
COPY examples/simple.caddyfile /etc/caddy/Caddyfile | ||
|
||
# See https://caddyserver.com/docs/conventions#file-locations for details | ||
ENV XDG_CONFIG_HOME /config | ||
Check warning on line 34 in Dockerfile
|
||
ENV XDG_DATA_HOME /data | ||
Check warning on line 35 in Dockerfile
|
||
|
||
EXPOSE 80 | ||
EXPOSE 443 | ||
EXPOSE 443/udp | ||
EXPOSE 2019 | ||
|
||
WORKDIR /srv | ||
|
||
CMD ["run", "--config", "/etc/caddy/Caddyfile"] | ||
ENTRYPOINT ["caddy"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice