Skip to content

Commit ef33a4b

Browse files
committed
feat: implement basic docker support probably
1 parent b70bf0e commit ef33a4b

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
name: Create and publish a Docker image
3+
4+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
5+
on:
6+
push:
7+
branches: ['main']
8+
release:
9+
types: [published]
10+
11+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
17+
jobs:
18+
build-and-push-image:
19+
runs-on: ubuntu-latest
20+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
21+
permissions:
22+
contents: read
23+
packages: write
24+
attestations: write
25+
id-token: write
26+
#
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
tags: |
44+
type=raw,value=dev,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
45+
type=semver,pattern={{version}}
46+
type=semver,pattern={{major}}.{{minor}}
47+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
48+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
49+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
50+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
51+
- name: Build and push Docker image
52+
id: push
53+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
54+
with:
55+
context: .
56+
push: true
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
60+
- name: Generate artifact attestation
61+
uses: actions/attest-build-provenance@v1
62+
with:
63+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
64+
subject-digest: ${{ steps.push.outputs.digest }}
65+
push-to-registry: true

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# syntax=docker/dockerfile:1
2+
FROM golang AS build-stage
3+
ADD . /src
4+
WORKDIR /src
5+
6+
RUN CGO_ENABLED=1 GOOS=linux go build -o /bin/twitterbridge .
7+
8+
FROM gcr.io/distroless/base-debian12 AS build-release-stage
9+
COPY --from=build-stage /bin/twitterbridge /bin/twitterbridge
10+
WORKDIR /config
11+
12+
ENV TWITTER_BRIDGE_DB_PATH="/config/sqlite/sqlite.db" \
13+
TWITTER_BRIDGE_SERVER_URL="http://127.0.0.1:3000" \
14+
TWITTER_BRIDGE_SERVER_PORT="3000"
15+
16+
CMD ["/bin/twitterbridge"]

config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ func ParseConfig() Config {
4242
}
4343

4444
// Get values from environment variables
45-
if url := os.Getenv("SERVER_URL"); url != "" {
45+
if url := os.Getenv("TWITTER_BRIDGE_SERVER_URL"); url != "" {
4646
config.URL = url
4747
}
4848

49-
if port := os.Getenv("SERVER_PORT"); port != "" {
49+
if port := os.Getenv("TWITTER_BRIDGE_SERVER_PORT"); port != "" {
5050
if portInt, err := strconv.Atoi(port); err == nil {
5151
config.Port = portInt
5252
}

0 commit comments

Comments
 (0)