Skip to content

Commit

Permalink
Build & Publish Sway Docker Image (FuelLabs#597)
Browse files Browse the repository at this point in the history
* Adding dockerfile & ci workflow for sway build-publish off master
  • Loading branch information
rfuelsh authored Jan 12, 2022
1 parent 6d2c367 commit cc24ce8
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io

jobs:
build:
Expand Down Expand Up @@ -103,3 +104,88 @@ jobs:
uses: katyo/publish-crates@v1
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

build-publish-master-image:
needs: build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
ghcr.io/fuellabs/sway
tags: |
type=sha
type=ref,event=branch
type=ref,event=tag
flavor: |
latest=${{ github.ref == 'refs/heads/master' }}
- 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: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push the image to ghcr.io
uses: docker/build-push-action@v2
with:
context: .
file: deployment/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

build-publish-release-image:
# Build & Publish Docker Image Per Sway Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
ghcr.io/fuellabs/sway
- 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: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push the image to ghcr.io
uses: docker/build-push-action@v2
with:
context: .
file: deployment/Dockerfile
push: true
tags: ${{ github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
28 changes: 28 additions & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Stage 1: Build
FROM rust:1.56 as builder

RUN apt-get update && \
apt-get install -y --no-install-recommends \
clang \
libclang-dev \
libssl-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /build/

COPY . .

RUN cargo build --release -p forc

# Stage 2: Run
FROM ubuntu:20.04 as run

RUN apt-get update && \
apt-get install -y --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /root/

COPY --from=builder /build/target/release/forc .

0 comments on commit cc24ce8

Please sign in to comment.