Dev #15
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
name: Docker CICD | |
on: | |
push: | |
branches: | |
- main | |
- testing | |
- dev | |
pull_request: | |
branches: | |
- main | |
jobs: | |
cicd-docker: | |
name: Cargo and npm build | |
runs-on: ubuntu-latest | |
environment: build | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
- name: Install stable toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
profile: minimal | |
override: true | |
components: rustfmt, clippy | |
- name: Cache cargo registry | |
uses: actions/[email protected] | |
with: | |
path: ~/.cargo/registry | |
key: docker-registry-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
docker-registry- | |
docker- | |
- name: Cache cargo index | |
uses: actions/[email protected] | |
with: | |
path: ~/.cargo/git | |
key: docker-index-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
docker-index- | |
docker- | |
- name: Generate Secret Key | |
run: | | |
head -c16 /dev/urandom > src/secret.key | |
- name: Cache cargo build | |
uses: actions/[email protected] | |
with: | |
path: target | |
key: docker-build-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
docker-build- | |
docker- | |
- name: Cargo check | |
uses: actions-rs/cargo@v1 | |
with: | |
command: check | |
- name: Cargo test | |
if: ${{ always() }} | |
uses: actions-rs/cargo@v1 | |
with: | |
command: test | |
- name: Rustfmt | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
profile: minimal | |
override: true | |
components: rustfmt | |
command: fmt | |
args: --all -- --check | |
- name: Rustfmt | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
profile: minimal | |
override: true | |
components: clippy | |
command: clippy | |
args: -- -D warnings | |
- name: Run cargo build | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: --release | |
- name: npm install, build, and test | |
working-directory: ./web | |
run: | | |
npm install | |
npm run build | |
# npm test | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist-without-markdown | |
path: | | |
web/dist | |
!web/dist/**/*.md | |
- name: Display structure of downloaded files | |
run: ls -R web/dist | |
- name: Copy app files and zip | |
run: | | |
mkdir -p app/stacker/dist | |
cp target/release/stacker app/stacker | |
cp -a web/dist/. app/stacker | |
cp docker/prod/Dockerfile app/Dockerfile | |
cd app | |
touch .env | |
tar -czvf ../app.tar.gz . | |
cd .. | |
- name: Upload app archive for Docker job | |
uses: actions/upload-artifact@v4 | |
with: | |
name: artifact-linux-docker | |
path: app.tar.gz | |
cicd-linux-docker: | |
name: CICD Docker | |
runs-on: ubuntu-latest | |
needs: cicd-docker | |
steps: | |
- name: Download app archive | |
uses: actions/download-artifact@v4 | |
with: | |
name: artifact-linux-docker | |
- name: Extract app archive | |
run: tar -zxvf app.tar.gz | |
- name: Display structure of downloaded files | |
run: ls -R | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- | |
name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
tags: trydirect/stacker:latest |