Skip to content
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

ci: add docker publish action #27

Merged
merged 8 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/actions/docker-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 'Docker publish image'

inputs:
docker_registry:
default: ghcr.io
require: true
image_name:
require: true
default_branch:
default: master
require: true
docker_context:
default: .
require: true
docker_platforms:
require: true
docker_file:
default: deployment/Dockerfile
require: true
docker_username:
require: true
docker_password:
require: true

runs:
using: 'composite'
steps:
- name: Extract metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ inputs.docker_registry }}/${{ inputs.image_name }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{raw}}
flavor: |
latest=${{ format('refs/heads/{0}', inputs.default_branch) == github.ref }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to the ghcr.io registry
uses: docker/login-action@v1
with:
registry: ${{ inputs.docker_registry }}
username: ${{ inputs.docker_username }}
password: ${{ inputs.docker_password }}

- name: Build and push the image to ghcr.io
uses: docker/build-push-action@v4
with:
context: ${{ inputs.docker_context }}
platforms: ${{ inputs.docker_platforms }}
file: ${{ inputs.docker_file }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
40 changes: 32 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ env:
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v1.24.3/dasel_linux_amd64
RUST_VERSION: 1.70.0
FUEL_CORE_VERSION: 0.18.3
IMAGE_NAME: ${{ github.repository }}

jobs:

verify-rust-version:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v3
# Ensure CI is using the same minimum toolchain specified in fuels Cargo.toml
Expand All @@ -31,7 +31,7 @@ jobs:
cargo-verifications:
needs:
- verify-rust-version
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -57,7 +57,7 @@ jobs:
run: ./run_tests.sh

publish-crates-check:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -73,14 +73,13 @@ jobs:
check-repo: false
ignore-unpublished-changes: true

publish:
publish-crates:
needs:
- cargo-verifications
- publish-crates-check

# Only do this job if publishing a release
# Only do this job if publishing a release
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204

steps:
- name: Checkout repository
Expand All @@ -100,3 +99,28 @@ jobs:
with:
publish-delay: 30000
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

publish-docker-image:
needs:
- cargo-verifications
runs-on: buildjet-4vcpu-ubuntu-2204
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Publish Docker image
uses: ./.github/actions/docker-publish
with:
image_name: ${{ env.IMAGE_NAME }}
docker_username: ${{ github.repository_owner }}
docker_password: ${{ secrets.GITHUB_TOKEN }}
docker_platforms: linux/amd64,linux/arm64

- uses: FuelLabs/.github/.github/actions/slack-notify-template@master
if: always() && (github.ref == 'refs/heads/master' || github.ref_type == 'tag')
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook: ${{ secrets.SLACK_WEBHOOK_NOTIFY_BUILD }}