fork/static-web-server

git clone https://git.julia.blue/fork/static-web-server

Jose Quintanachore: remove `pull_request` trigger from release-docker-devel workflow (#608)c298a6d

allow-symlink
4.4 KiB141 linesraw
1name: release-docker-devel
2
3on:
4  push:
5    branches:
6      - master
7    paths:
8      - .github/workflows/release.docker.devel.yml
9      - .cargo/config.toml
10      - Cargo.lock
11      - Cargo.toml
12      - src/**
13
14env:
15  TARGET_DIR: ./target
16
17jobs:
18  build-release:
19    runs-on: ubuntu-22.04
20    env:
21      CARGO_BIN: cargo
22      # Emit backtraces on panics.
23      RUST_BACKTRACE: 1
24      # SWS features for Cargo build
25      CARGO_FEATURES: "--features=all"
26      # When CARGO_BIN is set to CROSS, this is set to `--target matrix.target`.
27      TARGET_FLAGS: ""
28    strategy:
29      matrix:
30        build:
31          # DOCKER: jobs just work only for one target.
32          # If multiple targets are needed then refactor the workflow and the 'devel' Dockerfile to be Docker Multiarch.
33          - linux-musl
34        include:
35        - build: linux-musl
36          arch: linux/amd64
37          rust: stable
38          target: x86_64-unknown-linux-musl
39        - build: linux-gnu
40          arch: linux/amd64
41          rust: stable
42          target: x86_64-unknown-linux-gnu
43
44    outputs:
45      target: ${{ steps.target.outputs.target }}
46      arch: ${{ steps.arch.outputs.arch }}
47
48    steps:
49      - name: Checkout repository
50        uses: actions/checkout@v4
51        with:
52          fetch-depth: 1
53      - name: Install Rust
54        uses: dtolnay/rust-toolchain@stable
55        with:
56          toolchain: ${{ matrix.rust }}
57          target: ${{ matrix.target }}
58      - name: Set up Cross
59        shell: bash
60        run: |
61          echo "Installing cross..."
62          curl -sSL \
63            "https://github.com/cross-rs/cross/releases/download/v0.2.5/cross-${{ matrix.target }}.tar.gz" \
64            | sudo tar zxf - -C /usr/local/bin/ cross cross-util
65          cross -V
66          echo "CARGO_BIN=/usr/local/bin/cross" >> $GITHUB_ENV
67          echo "TARGET_FLAGS=--target=${{ matrix.target }}" >> $GITHUB_ENV
68          echo "TARGET_DIR=${{ env.TARGET_DIR }}/${{ matrix.target }}" >> $GITHUB_ENV
69
70      - name: Show command used for Cargo
71        run: |
72          echo "cargo command is: ${{ env.CARGO_BIN }}"
73          echo "target dir is: ${{ env.TARGET_DIR }}"
74      - name: Build release binary
75        run: |
76          ${{ env.CARGO_BIN }} build --bin static-web-server -vv --release ${{ env.CARGO_FEATURES }} ${{ env.TARGET_FLAGS }}
77      - name: Define target output
78        id: target
79        run: |
80          echo 'target=${{ matrix.target }}' >> "$GITHUB_OUTPUT"
81      - name: Define arch output
82        id: arch
83        run: |
84          echo 'arch=${{ matrix.arch }}' >> "$GITHUB_OUTPUT"
85      - name: Cache binary
86        uses: actions/cache@v4
87        with:
88          path: ${{ env.TARGET_DIR }}/release
89          # short-lived cache: https://github.com/actions/cache/blob/main/caching-strategies.md#creating-a-short-lived-cache
90          key: cache-${{ github.sha }}-${{ matrix.target }}
91
92  # NOTE: only one arch/target per Docker "kind" is supported.
93  # If multiple targets are needed then refactor the workflow and the 'devel' Dockerfile to be Docker Multiarch.
94  docker-image:
95    needs: ['build-release']
96    runs-on: ubuntu-22.04
97    permissions:
98      contents: read
99      packages: write
100    strategy:
101      matrix:
102        kind:
103          - scratch
104          - debian
105        include:
106          - kind: scratch
107            tag: devel
108          - kind: debian
109            tag: devel-debian
110        target:
111          - ${{ needs.build-release.outputs.target }}
112        arch:
113          - ${{ needs.build-release.outputs.arch }}
114    steps:
115      - name: Checkout repository
116        uses: actions/checkout@v4
117        with:
118          fetch-depth: 1
119      - name: Restore cache
120        uses: actions/cache/restore@v4
121        with:
122          path: ${{ env.TARGET_DIR }}/${{ matrix.target }}/release
123          key: cache-${{ github.sha }}-${{ matrix.target }}
124      - name: Copy binary
125        run: |
126            cp ${{ env.TARGET_DIR }}/${{ matrix.target }}/release/static-web-server ./docker/devel/
127
128      - name: Login to ghcr.io
129        uses: docker/login-action@v3
130        with:
131          registry: ghcr.io
132          username: ${{ github.actor }}
133          password: ${{ secrets.GITHUB_TOKEN }}
134      - name: Build and push (${{ matrix.kind }})
135        uses: docker/build-push-action@v6
136        with:
137          push: true
138          context: .
139          platforms: ${{ matrix.arch }}
140          file: ./docker/devel/Dockerfile.${{ matrix.kind }}
141          tags: ghcr.io/static-web-server/static-web-server:${{ matrix.tag }}