Skip to content

Commit 619cb8e

Browse files
authored
Merge pull request #15 from apptweak/misc/davida/add-gh-action-to-publish-docker-image
Add workflow to lint Dockerfile and publish docker image on push
2 parents b470e43 + a9bf0a7 commit 619cb8e

File tree

5 files changed

+110
-7
lines changed

5 files changed

+110
-7
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and publish docker image
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
- use_head_commit
8+
tags:
9+
# any tag names starting with 'v'
10+
- 'v*'
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
# Gives the action the ability to mint the OIDC token necessary to request a Sigstore signing certificate
21+
id-token: write
22+
# Permission necessary to persist the attestation
23+
attestations: write
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
- name: Set-up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
with:
30+
platforms: linux/amd64
31+
- name: Log in to the Github Container registry
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@v5
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
tags: |
43+
type=ref,event=branch
44+
type=ref,event=pr
45+
type=semver,pattern={{version}}
46+
type=semver,pattern={{major}}.{{minor}}
47+
- name: Build and push Docker image
48+
id: push
49+
uses: docker/build-push-action@v6
50+
with:
51+
context: .
52+
push: true
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
- name: Generate artifact attestation
56+
uses: actions/attest-build-provenance@v2
57+
with:
58+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
59+
subject-digest: ${{ steps.push.outputs.digest }}
60+
push-to-registry: true

.github/workflows/hadolint.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Hadolint - Dockerfile linting
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
types: [opened, synchronize]
6+
paths:
7+
- "Dockerfile"
8+
jobs:
9+
hadolint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: hadolint/hadolint-action@v3.1.0
14+
with:
15+
verbose: true

.hadolint.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# list of rules: https://github.com/hadolint/hadolint/wiki
2+
ignored:
3+
- DL3008 # Pin versions in apt-get install - https://github.com/hadolint/hadolint/wiki/DL3008
4+
# - DL3018 # Pin versions in apk add - https://github.com/hadolint/hadolint/wiki/DL3018
5+
# - DL3028 # Pin version in gem install - https://github.com/hadolint/hadolint/wiki/DL3028
6+
7+
trustedRegistries:
8+
- docker.io
9+
- "*.gcr.io"
10+
- "*.ecr.eu-west-1.amazonaws.com"
11+
12+
override:
13+
warning:
14+
- DL3028 # Pin version in gem install - https://github.com/hadolint/hadolint/wiki/DL3028

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.4.7
1+
3.4.8

Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
FROM ruby:3.4.7
2-
3-
LABEL maintainer="Devex <info@apptweak.com>"
1+
ARG RUBY_VERSION=3.4
2+
FROM ruby:${RUBY_VERSION}
3+
4+
ARG BUNDLER_VERSION="2.6.7"
5+
ARG NODE_VERSION=14
6+
ARG BUILD_DATE=
7+
ARG CVS_REF=
8+
9+
LABEL maintainer="DevEx Team <squad_devex@apptweak.com>"
10+
LABEL org.opencontainers.image.source https://github.com/apptweak/pronto-ruby
11+
LABEL org.opencontainers.image.title="AppTweak Pronto Ruby Runner"
12+
LABEL org.opencontainers.image.description="GitHub Action for running Pronto code review automation for Ruby projects"
413
LABEL org.opencontainers.image.source="https://github.com/apptweak/pronto-ruby"
5-
6-
ARG BUNDLER_VERSION="2.7.2"
14+
LABEL org.opencontainers.image.url="https://github.com/apptweak/pronto-ruby"
15+
LABEL org.opencontainers.image.vendor="AppTweak"
16+
LABEL org.opencontainers.image.version=${CVS_REF}
17+
LABEL org.opencontainers.image.created=${BUILD_DATE}
718

819
RUN apt-get update && apt-get install -y curl
920

1021
RUN apt-get update && \
1122
apt-get install --no-install-recommends -y \
12-
ruby-dev \
1323
build-essential \
1424
cmake \
1525
git \
@@ -20,6 +30,10 @@ RUN apt-get update && \
2030
libz-dev \
2131
&& rm -rf /var/lib/apt/lists/*
2232

33+
# Make sure to use bash with pipefail in case something
34+
# fails while being piped to another command in the docker-build
35+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
36+
2337
RUN gem install bundler --version "${BUNDLER_VERSION}"
2438

2539
WORKDIR /runner

0 commit comments

Comments
 (0)