Skip to content

Commit 5aa6d3b

Browse files
committed
feat: upgrade github actions + extract frontend build away from docker
1 parent 6887acf commit 5aa6d3b

File tree

6 files changed

+26
-61
lines changed

6 files changed

+26
-61
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.cache/
22
.git/
33
.vscode/
4-
build/
54
docs/
65
node_modules/
76
tests/

.github/workflows/main.yml

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- id: nvm
2121
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
2222

23-
- uses: actions/setup-node@v2.2.0
23+
- uses: actions/setup-node@v3
2424
with:
2525
node-version: '${{ steps.nvm.outputs.NVMRC }}'
2626
cache: yarn
@@ -42,7 +42,7 @@ jobs:
4242
- id: nvm
4343
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
4444

45-
- uses: actions/setup-node@v2.2.0
45+
- uses: actions/setup-node@v3
4646
with:
4747
node-version: '${{ steps.nvm.outputs.NVMRC }}'
4848
cache: yarn
@@ -78,7 +78,7 @@ jobs:
7878
- id: nvm
7979
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
8080

81-
- uses: actions/setup-node@v2.2.0
81+
- uses: actions/setup-node@v3
8282
with:
8383
node-version: '${{ steps.nvm.outputs.NVMRC }}'
8484
cache: yarn
@@ -88,13 +88,6 @@ jobs:
8888
with:
8989
go-version: '^1.21.1'
9090

91-
- name: Set up QEMU
92-
uses: docker/setup-qemu-action@v3
93-
- name: Set up Docker Buildx
94-
uses: docker/setup-buildx-action@v3
95-
with:
96-
platforms: linux/amd64,linux/arm64
97-
9891
- run: yarn install --frozen-lockfile
9992

10093
- name: Build
@@ -104,20 +97,11 @@ jobs:
10497
make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} start-docker
10598
10699
- if: startsWith(github.ref, 'refs/tags/')
107-
run: make save-docker
108-
109-
- if: startsWith(github.ref, 'refs/tags/')
110-
uses: actions/[email protected]
100+
uses: actions/upload-artifact@v3
111101
with:
112102
name: smocker-bin
113103
path: ./build/smocker.tar.gz
114104

115-
- if: startsWith(github.ref, 'refs/tags/')
116-
uses: actions/[email protected]
117-
with:
118-
name: smocker-docker
119-
path: /tmp/smocker.tar
120-
121105
deploy:
122106
needs: [lint, test, build]
123107
if: startsWith(github.ref, 'refs/tags/')
@@ -128,30 +112,31 @@ jobs:
128112
- id: extract_ref
129113
run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/})
130114

131-
- uses: actions/download-artifact@v2
115+
- uses: actions/download-artifact@v3
132116
with:
133117
name: smocker-bin
134118
path: ./build
135119

136-
- uses: actions/download-artifact@v2
137-
with:
138-
name: smocker-docker
139-
path: /tmp
140-
141-
- run: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} load-docker
120+
- run: cd build && tar -xvf smocker.tar.gz
142121

143122
- name: Docker login
144-
uses: docker/login-action@v1.10.0
123+
uses: docker/login-action@v3
145124
with:
146125
username: ${{ secrets.DOCKER_USERNAME }}
147126
password: ${{ secrets.DOCKER_PASSWORD }}
148127

128+
- name: Set up QEMU
129+
uses: docker/setup-qemu-action@v3
130+
- name: Set up Docker Buildx
131+
uses: docker/setup-buildx-action@v3
132+
with:
133+
platforms: linux/amd64,linux/arm64
134+
149135
- name: Deploy on Docker registry
150136
run: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} deploy-docker
151137

152138
- name: Deploy on GitHub releases
153-
uses: softprops/action-gh-release@v0.1.5
139+
uses: softprops/action-gh-release@v1
154140
with:
155141
files: build/smocker.tar.gz
156-
env:
157-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
142+
token: ${{ secrets.GH_TOKEN }}

Dockerfile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@ COPY Makefile main.go ./
99
COPY server/ ./server/
1010
RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build
1111

12-
FROM node:16-bullseye AS build-frontend
13-
WORKDIR /wd
14-
ENV PARCEL_WORKERS 1
15-
COPY package.json yarn.lock ./
16-
RUN yarn install --frozen-lockfile --ignore-scripts --network-timeout 300000
17-
COPY tsconfig.json ./
18-
COPY client/ ./client/
19-
RUN yarn build
20-
2112
FROM alpine
2213
WORKDIR /opt
2314
EXPOSE 8080 8081
15+
COPY build/client client/
2416
COPY --from=build-backend /go/src/github.com/Thiht/smocker/build/* /opt/
25-
COPY --from=build-frontend /wd/build/* /opt/
2617
CMD ["/opt/smocker"]

Makefile

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ clean:
108108

109109
.PHONY: build-docker
110110
build-docker:
111-
docker buildx build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest --platform linux/arm64,linux/amd64 .
111+
docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest .
112112
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG)
113113

114114
.PHONY: start-docker
@@ -129,9 +129,9 @@ optimize:
129129

130130
build/smocker.tar.gz:
131131
$(MAKE) build
132-
yarn install --frozen-lockfile --ignore-scripts --network-timeout 300000
132+
yarn install --frozen-lockfile --ignore-scripts
133133
yarn build
134-
cd build/; tar cvf smocker.tar.gz *
134+
cd build/; tar -cvf smocker.tar.gz *
135135

136136
.PHONY: release
137137
release: build/smocker.tar.gz
@@ -144,18 +144,10 @@ start-release: clean build/smocker.tar.gz
144144
start-caddy: $(CADDY)
145145
$(CADDY) run
146146

147-
.PHONY: save-docker
148-
save-docker:
149-
docker save --output /tmp/smocker.tar $(DOCKER_IMAGE):latest
150-
151-
.PHONY: load-docker
152-
load-docker:
153-
docker load --input /tmp/smocker.tar
154-
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG)
155-
156147
.PHONY: deploy-docker
157148
deploy-docker:
149+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; docker buildx create --use
158150
ifdef IS_SEMVER
159-
docker push $(DOCKER_IMAGE):latest
151+
docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest --platform linux/arm/v7,linux/arm64/v8,linux/amd64 .
160152
endif
161-
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
153+
docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --platform linux/arm/v7,linux/arm64/v8,linux/amd64 .

main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import (
99
log "github.com/sirupsen/logrus"
1010
)
1111

12-
var (
13-
appName, buildVersion, buildCommit, buildDate string // nolint
14-
)
12+
var appName, buildVersion, buildCommit, buildDate string // nolint
1513

1614
func parseConfig() (c config.Config) {
1715
c.Build = config.Build{
@@ -28,7 +26,7 @@ func parseConfig() (c config.Config) {
2826
flag.StringVar(&c.ConfigBasePath, "config-base-path", "/", "Base path applied to Smocker UI")
2927
flag.IntVar(&c.ConfigListenPort, "config-listen-port", 8081, "Listening port of Smocker administration server")
3028
flag.IntVar(&c.MockServerListenPort, "mock-server-listen-port", 8080, "Listening port of Smocker mock server")
31-
flag.StringVar(&c.StaticFiles, "static-files", ".", "Location of the static files to serve (index.html, etc.)")
29+
flag.StringVar(&c.StaticFiles, "static-files", "client", "Location of the static files to serve (index.html, etc.)")
3230
flag.IntVar(&c.HistoryMaxRetention, "history-retention", 0, "Maximum number of calls to keep in the history per session (0 = no limit)")
3331
flag.StringVar(&c.PersistenceDirectory, "persistence-directory", "", "If defined, the directory where the sessions will be synchronized")
3432
flag.BoolVar(&c.TLSEnable, "tls-enable", false, "Enable TLS using the provided certificate")

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"targets": {
1919
"default": {
20-
"distDir": "./build",
20+
"distDir": "./build/client",
2121
"publicUrl": "./assets"
2222
}
2323
},

0 commit comments

Comments
 (0)