@@ -2,163 +2,90 @@ name: Docker CICD
22
33on :
44 push :
5- branches :
6- - master
7- - testing
5+ branches : [main, dev]
86 pull_request :
9- branches :
10- - master
7+ branches : [main, dev]
118
129jobs :
13- cicd-linux-docker :
14- name : Cargo and npm build
15- # runs-on: ubuntu-latest
16- runs-on : [self-hosted, linux]
10+ build :
11+ name : Build & Test
12+ runs-on : ubuntu-latest
1713 steps :
18- - name : Checkout sources
19- uses : actions/checkout@v4
14+ - uses : actions/checkout@v4
2015
21- - name : Install stable toolchain
22- uses : actions-rs/ toolchain@v1
16+ - name : Install Rust toolchain
17+ uses : dtolnay/rust- toolchain@stable
2318 with :
24- toolchain : stable
25- profile : minimal
26- override : true
2719 components : rustfmt, clippy
2820
29- - name : Cache cargo registry
30- uses : actions/cache@v4
31- with :
32- path : ~/.cargo/registry
33- key : docker-registry-${{ hashFiles('**/Cargo.lock') }}
34- restore-keys : |
35- docker-registry-
36- docker-
37-
38- - name : Cache cargo index
39- uses : actions/cache@v4
40- with :
41- path : ~/.cargo/git
42- key : docker-index-${{ hashFiles('**/Cargo.lock') }}
43- restore-keys : |
44- docker-index-
45- docker-
21+ - name : Cache Rust dependencies
22+ uses : Swatinem/rust-cache@v2
4623
4724 - name : Generate Secret Key
48- run : |
49- head -c16 /dev/urandom > src/secret.key
25+ run : head -c16 /dev/urandom > src/secret.key
5026
51- - name : Cache cargo build
52- uses : actions/cache@v4
53- with :
54- path : target
55- key : docker-build-${{ hashFiles('**/Cargo.lock') }}
56- restore-keys : |
57- docker-build-
58- docker-
59-
60- - name : Cargo check
61- uses : actions-rs/cargo@v1
62- with :
63- command : check
27+ - name : Check
28+ run : cargo check
6429
65- - name : Cargo test
66- if : ${{ always() }}
67- uses : actions-rs/cargo@v1
68- with :
69- command : test
30+ - name : Format check
31+ run : cargo fmt --all -- --check
7032
71- - name : Rustfmt
72- uses : actions-rs/toolchain@v1
73- with :
74- toolchain : stable
75- profile : minimal
76- override : true
77- components : rustfmt
78- command : fmt
79- args : --all -- --check
80-
81- - name : Rustfmt
82- uses : actions-rs/toolchain@v1
83- with :
84- toolchain : stable
85- profile : minimal
86- override : true
87- components : clippy
88- command : clippy
89- args : -- -D warnings
90-
91- - name : Run cargo build
92- uses : actions-rs/cargo@v1
93- with :
94- command : build
95- args : --release
33+ - name : Clippy
34+ run : cargo clippy -- -D warnings
35+
36+ - name : Test
37+ run : cargo test
9638
97- - name : npm install, build, and test
39+ - name : Build release
40+ run : cargo build --release
41+
42+ - name : Build frontend
9843 working-directory : ./web
9944 run : |
100- npm install
45+ npm ci
10146 npm run build
102- # npm test
10347
104- - name : Archive production artifacts
105- uses : actions/upload-artifact@v4
106- with :
107- name : dist-without-markdown
108- path : |
109- web/dist
110- !web/dist/**/*.md
111-
112- # - name: Archive code coverage results
113- # uses: actions/upload-artifact@v4
114- # with:
115- # name: code-coverage-report
116- # path: output/test/code-coverage.html
117- - name : Display structure of downloaded files
118- run : ls -R web/dist
119-
120- - name : Copy app files and zip
48+ - name : Package app
12149 run : |
12250 mkdir -p app/stackdog/dist
123- cp target/release/stackdog app/stackdog
124- cp -a web/dist/. app/stackdog
51+ cp target/release/stackdog app/stackdog/
52+ cp -a web/dist/. app/stackdog/
12553 cp docker/prod/Dockerfile app/Dockerfile
126- cd app
127- touch .env
128- tar -czvf ../app.tar.gz .
129- cd ..
54+ touch app/.env
55+ tar -czf app.tar.gz -C app .
13056
131- - name : Upload app archive for Docker job
57+ - name : Upload build artifact
13258 uses : actions/upload-artifact@v4
13359 with :
134- name : artifact-linux-docker
60+ name : app-archive
13561 path : app.tar.gz
62+ retention-days : 1
13663
137- cicd-docker :
138- name : CICD Docker
139- # runs-on: ubuntu-latest
140- runs-on : [self-hosted, linux]
141- needs : cicd-linux-docker
64+ docker :
65+ name : Docker Build & Push
66+ runs-on : ubuntu-latest
67+ needs : build
14268 steps :
143- - name : Download app archive
69+ - name : Download build artifact
14470 uses : actions/download-artifact@v4
14571 with :
146- name : artifact-linux-docker
72+ name : app-archive
14773
148- - name : Extract app archive
149- run : tar -zxvf app.tar.gz
74+ - name : Extract archive
75+ run : tar -xzf app.tar.gz
15076
151- - name : Display structure of downloaded files
152- run : ls -R
77+ - name : Set up Docker Buildx
78+ uses : docker/setup-buildx-action@v3
15379
15480 - name : Login to Docker Hub
15581 uses : docker/login-action@v3
15682 with :
15783 username : ${{ secrets.DOCKER_USERNAME }}
15884 password : ${{ secrets.DOCKER_PASSWORD }}
15985
160- - name : Docker build and publish
86+ - name : Build and push
16187 uses : docker/build-push-action@v6
16288 with :
89+ context : .
16390 push : true
16491 tags : trydirect/stackdog:latest
0 commit comments