-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
Automatically Run Tests on PR and Push Docker Image #38
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3f9b250
Add github actions tests
withinboredom 42ed376
native running is a bit more complicated
withinboredom 735d8ef
Add actual builder
withinboredom 90a954e
Add runner os
withinboredom 3737890
and this one too
withinboredom 3481078
fix naming
withinboredom 504db86
checkout submodules
withinboredom ab12434
remove backslash
withinboredom de1e183
fix test runner
withinboredom 3ef12d0
Add documentation and fix up docker deployment stuff
withinboredom 0d2bbdc
use different caching method
withinboredom 3c2a243
also for tests
withinboredom 19e7405
update caches for main
withinboredom 88f6b0a
specify target
withinboredom 03cf5d8
specify target
withinboredom 61c5f3e
remove docker cache from tests
withinboredom 011578b
Optimize dockerfile for better caching
withinboredom 7181d2d
significantly speed up cached builds
withinboredom 0ecf987
use gha cache
withinboredom 785fafd
update action versions
withinboredom a8166e2
only build one os for now
withinboredom ffe4e48
test non-code change
withinboredom 847069d
Update docker actions
withinboredom b20f847
fix typo
withinboredom 46c0edc
fake commit
withinboredom 38ed629
reset changes
withinboredom 8483f35
build other platforms for tests
withinboredom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: Build and push Docker image (latest) | ||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- v* | ||
jobs: | ||
docker-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@master | ||
with: | ||
install: true | ||
|
||
- name: Build test image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ./ | ||
file: Dockerfile | ||
push: false | ||
pull: true | ||
target: builder | ||
tags: ${{secrets.REGISTRY_LOGIN_SERVER}}/${{ secrets.REGISTRY_USERNAME }}/frankenphp:${{ github.sha }}-builder | ||
builder: ${{ steps.buildx.outputs.name }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
outputs: type=docker,dest=/tmp/.builder.tar | ||
|
||
- name: Run tests | ||
run: | | ||
docker load -i /tmp/.builder.tar | ||
docker run --rm ${{secrets.REGISTRY_LOGIN_SERVER}}/${{ secrets.REGISTRY_USERNAME }}/frankenphp:${{ github.sha }}-builder "go test" | ||
push-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Docker Login | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{secrets.REGISTRY_LOGIN_SERVER}} | ||
username: ${{secrets.REGISTRY_USERNAME}} | ||
password: ${{secrets.REGISTRY_PASSWORD}} | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
# list of Docker images to use as base name for tags | ||
images: | | ||
${{ secrets.REGISTRY_LOGIN_SERVER }}/${{ secrets.REGISTRY_REPO }}/frankenphp | ||
# generate Docker tags based on the following events/attributes | ||
tags: | | ||
type=schedule | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
type=sha | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@master | ||
with: | ||
install: true | ||
|
||
- name: Setup QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Build and Push Image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ./ | ||
file: Dockerfile | ||
push: true | ||
pull: true | ||
target: final | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
builder: ${{ steps.buildx.outputs.name }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Tests | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
docker-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@master | ||
with: | ||
install: true | ||
|
||
- name: Build test image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ./ | ||
file: Dockerfile | ||
push: false | ||
pull: true | ||
target: builder | ||
tags: ${{secrets.REGISTRY_LOGIN_SERVER}}/${{ secrets.REGISTRY_USERNAME }}/frankenphp:${{ github.sha }}-builder | ||
builder: ${{ steps.buildx.outputs.name }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
outputs: type=docker,dest=/tmp/.builder.tar | ||
|
||
- name: Run tests | ||
run: | | ||
docker load -i /tmp/.builder.tar | ||
docker run --rm ${{secrets.REGISTRY_LOGIN_SERVER}}/${{ secrets.REGISTRY_USERNAME }}/frankenphp:${{ github.sha }}-builder "go test" | ||
push-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Docker Login | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{secrets.REGISTRY_LOGIN_SERVER}} | ||
username: ${{secrets.REGISTRY_USERNAME}} | ||
password: ${{secrets.REGISTRY_PASSWORD}} | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
# list of Docker images to use as base name for tags | ||
images: | | ||
${{ secrets.REGISTRY_LOGIN_SERVER }}/${{ secrets.REGISTRY_REPO }}/frankenphp | ||
# generate Docker tags based on the following events/attributes | ||
tags: | | ||
type=schedule | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
type=sha | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@master | ||
with: | ||
install: true | ||
|
||
- name: Setup QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Build and Push Image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ./ | ||
file: Dockerfile | ||
push: true | ||
pull: true | ||
target: final | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
builder: ${{ steps.buildx.outputs.name }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a new line here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,14 +85,18 @@ COPY --from=golang:bullseye /usr/local/go /usr/local/go | |
WORKDIR /go/src/app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go get -v ./... | ||
RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get | ||
|
||
RUN mkdir caddy && cd caddy | ||
COPY go.mod go.sum ./ | ||
COPY caddy/go.mod caddy/go.sum ./caddy/ | ||
|
||
RUN go get -v ./... | ||
RUN cd caddy && go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get | ||
|
||
COPY . . | ||
COPY *.* . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed this to |
||
COPY caddy caddy | ||
COPY C-Thread-Pool C-Thread-Pool | ||
COPY internal internal | ||
COPY testdata testdata | ||
|
||
# todo: automate this? | ||
# see https://github.com/docker-library/php/blob/master/8.2-rc/bullseye/zts/Dockerfile#L57-L59 for php values | ||
|
@@ -103,6 +107,8 @@ RUN cd caddy/frankenphp && \ | |
cp frankenphp /usr/local/bin && \ | ||
cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile | ||
|
||
ENTRYPOINT ["/bin/bash","-c"] | ||
|
||
FROM php:8.2.0RC4-zts-bullseye AS final | ||
|
||
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Using GitHub Actions | ||
|
||
This repository builds and deploys the Docker image to [Docker Hub](https://hub.docker.com/r/dunglas/frankenphp) on | ||
every approved pull request or on your own fork once setup. | ||
|
||
## Setting up GitHub Actions | ||
|
||
In the repository settings, under secrets, add the following secrets: | ||
|
||
- `REGISTRY_LOGIN_SERVER`: The docker registry to use (e.g. `docker.io`). | ||
- `REGISTRY_USERNAME`: The username to use to login to the registry (e.g. `dunglas`). | ||
- `REGISTRY_REPO`: The repository to use (e.g. `dunglas`). | ||
- `REGISTRY_PASSWORD`: The password to use to login to the registry (e.g. an access key). | ||
|
||
## Building and pushing the image | ||
|
||
1. Create a pull request or push to your fork. | ||
2. GitHub Actions will build the image and run any tests. | ||
3. If the build is successful, the image will be pushed to the registry using the `pr-x`, where `x` is the PR number, as the tag. | ||
|
||
## Deploying the image | ||
|
||
1. Once the pull request is merged, GitHub Actions will again run the tests and build a new image. | ||
2. If the build is successful, the `main` tag will be updated in the Docker registry. | ||
|
||
## Releases | ||
|
||
1. Create a new tag in the repository. | ||
2. GitHub Actions will build the image and run any tests. | ||
3. If the build is successful, the image will be pushed to the registry using the tag name as the tag (e.g. `v1.2.3` and `v1.2` will be created). | ||
4. The `latest` tag will also be updated. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'll add a new line here.