Skip to content

Commit 68ae744

Browse files
committed
Add CI pipeline
1 parent b046d17 commit 68ae744

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.github/workflows/ci-pipeline.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: CI Pipeline
2+
3+
# This workflow build and run tests inside the dev container
4+
# only after the pull request is merged to main branch.
5+
# Once tests are successful it builds and pushes the
6+
# smaller size production image with multiarch suppport.
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
# To be removed after testing
12+
pull_request:
13+
branches: [ "main" ]
14+
15+
env:
16+
# Use docker.io for Docker Hub if empty
17+
REGISTRY: ghcr.io
18+
# github.repository as <account>/<repo>
19+
IMAGE_NAME: ${{ github.repository }}
20+
TEST_TAG: user/app:test
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
# This is used to complete the identity challenge
29+
# with sigstore/fulcio when running outside of PRs.
30+
id-token: write
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v3
35+
36+
- name: Set up QEMU
37+
uses: docker/setup-qemu-action@v2
38+
39+
# Install the cosign tool except on PR
40+
# https://github.com/sigstore/cosign-installer
41+
- name: Install cosign
42+
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
43+
with:
44+
cosign-release: 'v2.1.1'
45+
46+
# Workaround: https://github.com/docker/build-push-action/issues/461
47+
- name: Setup Docker buildx
48+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
49+
50+
# Login against a Docker registry except on PR
51+
# https://github.com/docker/login-action
52+
- name: Log into registry ${{ env.REGISTRY }}
53+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
54+
with:
55+
registry: ${{ env.REGISTRY }}
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
# Build and push Docker image with Buildx
60+
# https://github.com/docker/build-push-action
61+
- name: Build and push test image
62+
id: build-test
63+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
64+
with:
65+
context: .
66+
load: true
67+
target: dev
68+
tags: ${{ env.TEST_TAG }}
69+
cache-from: type=gha
70+
cache-to: type=gha,mode=max
71+
72+
- name: Test
73+
run: |
74+
docker run --rm ${{ env.TEST_TAG }} make ci-test
75+
76+
# Extract metadata (tags, labels) for Docker
77+
# https://github.com/docker/metadata-action
78+
- name: Extract Docker metadata
79+
id: meta
80+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
81+
with:
82+
# list of Docker images to use as base name for tags
83+
images: |
84+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
85+
# generate Docker tags based on the following events/attributes
86+
tags: |
87+
type=sha
88+
89+
# Build and push Docker image with Buildx
90+
# https://github.com/docker/build-push-action
91+
- name: Build and push Docker image
92+
id: build-and-push
93+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
94+
with:
95+
context: .
96+
target: http_app
97+
platforms: linux/amd64,linux/arm64
98+
push: true
99+
tags: ${{ steps.meta.outputs.tags }}
100+
labels: ${{ steps.meta.outputs.labels }}
101+
cache-from: type=gha
102+
cache-to: type=gha,mode=max
103+
104+
# Sign the resulting Docker image digest except on PRs.
105+
# This will only write to the public Rekor transparency log when the Docker
106+
# repository is public to avoid leaking data. If you would like to publish
107+
# transparency data even for private images, pass --force to cosign below.
108+
# https://github.com/sigstore/cosign
109+
- name: Sign the published Docker image
110+
env:
111+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
112+
TAGS: ${{ steps.meta.outputs.tags }}
113+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
114+
# This step uses the identity token to provision an ephemeral certificate
115+
# against the sigstore community Fulcio instance.
116+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)